.NET MAUI Data Binding with MVVM & XAML [5 of 8] | .NET MAUI for Beginners
Why Stack Overflow recommends it
Stack Overflow users link it as the tutorial they followed for MVVM and Community Toolkit commands in .NET MAUI, and cite it when their own bindings or ICommand setups do not behave like the video.
Recommended by 1 people across 1 different months, 2022 to 2024.
What it is
Part 5 of the official .NET MAUI for Beginners series from the dotnet channel, presented by James Montemagno. It introduces the MVVM pattern and data binding in XAML, then makes a previously built UI functional using the .NET Community Toolkit (ObservableProperty, RelayCommand).
What people said
Recommends Andy Horton · 2023-09 · Stack Overflow · on “ICommand Command not working in Maui Preview 11”
In the end I went with the community toolkit and the RealyCommand (See Videos YouTube comments for RelayCommand rather than ICommand). [this video] I just could not get ICommand to work properly for some reason and I have my button inside a .NET MAUI Carousel view. I also needed to use the full path address in the XAML (as per the video): e.g. <Button Text="Submit" Grid.Column="0" Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodels:MonitoringSubmissionViewModel}}, Path=ShowMessageCommand}" /> to reach my relay command code method in my partial MVVM class: public partial class MonitoringSubmissionViewModel : ObservableCollection<CheckListDataBoundItem>, INotifyPropertyChanged
Cites Andrija · 2022-08 · Stack Overflow · on “RelativeSource in MAUI control not bound”
I'm going through simple example explained in video: [this video] At 16. minute (timestamp in link above), he implements the Delete Command on SwipeItem. In my local project, everything worked so far, but Delete Command is never triggered. I checked source generators, DeleteCommand exists. My XAML: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns=" [LINK] " xmlns:x=" [LINK] " x:Class="MauiApp1.MainPage" xmlns:viewmodel="clr-namespace:MauiApp1.ViewModel" x:DataType="viewmodel:MainViewModel"> <Grid RowDefinitions="100, Auto, *" ColumnDefinitions=".75*, .25*" Padding="10" RowSpacing="10" ColumnSpacing="10"> <Image Grid.ColumnSpan="2" Source="tom.jpg" BackgroundColor="Transparent"></Image>
Cites eop3 · 2023-12 · Stack Overflow · on “How to use events with MVVM in .NET MAUI?”
I am learning .NET MAUI, and the recommended architecture in this video tutorial [this video] is MVVM. It uses attributes from the the MVVM toolkit (CommunityToolkit.MVVM) like [ObservableProperty]. I am needing to use this gesture recognizer in my XAML: <Button.GestureRecognizers> <PointerGestureRecognizer PointerEntered="ButtonOnPointerEntered" PointerExited="ButtonOnPointerExit"/> </Button.GestureRecognizers> PointerEntered and PointerExited both need a method signature of void MethodName(object sender, EventArgs e) . In MVVM architecture (as I understand) you aren't supposed to have any code in the code-behind besides InitializeComponent() or any dependencies, but I haven't been able to find
Cites Ch1h0 · 2023-12 · Stack Overflow · on “Data Binding for Flyout page "'No property, BindableProperty, or event found for "Command", or mismatching type between value and property."”
I'm developing a mobile app using .Net MAUI and having trouble with data binding in XAML. I have MainPage.xaml that receives data from MainPageViewModel.cs which inherits from ObservableObject . In Flyout.cs , I have Title , IconSource , and Command and get them in <DataTemplate> in Mainpage.xaml . I pass values to each of the property in <CollectionView.ItemSource> and only to Command , I am passing a string of method that is defined in MainPageViewModel.xaml.cs . I am confused about how to perform data binding here. Values for Title and IconSource are bound correctly and visible, but only Command is not working. How can I get this to work? MainPage.xaml: <?xml version="1.0" encoding="utf-8
Cites 難波八郎 · 2024-05 · Stack Overflow · on “.NET MAUI CommunityToolkit.Mvvm ICommand”
I have a question about .NET MAUI. I'm learning from the following site: [this video] . I'm having trouble with ICommand errors, even though I should have downloaded CommunityToolkit.Mvvm as per the video. As shown in the image, ICommand cannot be found within the dependency [CommunityToolkit.Mvvm.SourceGenerators.dll]. Could it be because I'm using net8.0-android? The video is based on net6.0-android. If anyone knows the reason, I would appreciate your advice. I tried to do same thing with video.