you set the binding to:
<vm:MainViewModel/>
But above you state the class/file name is
ViewModel.cs
In the
ContentView.xaml
, use:
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyProject.MainView"
BackgroundColor="White"
xmlns:local="clr-namespace:MyProject.Views;assembly=MyProject.Mobile"
xmlns:vm="clr-namespace:MyProject.ViewModels;assembly=MyProject.Mobile"
NavigationPage.HasNavigationBar="False"
x:DataType="vm:MainViewModel">
Also set
XmlCompilationOptions.Compile
in
Assembly.cs
.
Watch this video for more information on bindings & MVVM:
Faster & Safer XAML with Compiled Bindings in Xamarin.Forms & .NET MAUI[
^]
Also, I highly recommend using ... Watch this video as to why:
Benefits of .NET MAUI over Xamarin/Xamarin.Forms - Live Stream Highlights[
^]
James wotks for Microsoft, and Xamarin before that. He has other videos that will benefit you greatly.