The .NET MAUI Community Toolkit is a community-contributed set of open-source add-ons for .NET MAUI. It groups commonly needed features outside the core product, including popup views, behaviors, and validation helpers, so an app can add capabilities without building every control extension from scratch. section 9.2 section 11.1.2
Add the CommunityToolkit.Maui NuGet package to the app, then initialize the toolkit on the MAUI host builder in MauiProgram.cs before using its APIs. In XAML, import the relevant toolkit namespace with an XML prefix; in C#, import the corresponding CommunityToolkit.Maui namespace. section 6.2.2 section 9.2
Use toolkit features where they remove repeated UI plumbing:
- Create a Popup for temporary UI such as a selectable genre list or movie-details view. Convert a ContentPage-based template to inherit from Popup, replace the XAML root with mct:Popup, remove the page Title, and set a size when needed. section 6.2.2
- Attach EventToCommandBehavior to a control when an event should invoke a ViewModel command. A CheckBox can respond to CheckedChanged by calling a command with the current bound item as its parameter. section 9.2
- Use included validation behaviors as a starting point for common input checks. Pair validation feedback with suitable input configuration, such as a numeric keyboard for numeric entry. section 11.1.2
Persist a completed to-do item from a CheckBox
Bind a CheckBox’s IsChecked property two-way to a Done value. Add EventToCommandBehavior beneath CheckBox.Behaviors, set EventName to CheckedChanged, and bind Command to CompleteTodoCommand on the page’s ViewModel. When the user checks or unchecks the item, the command updates the database and the completed state remains after reopening the app. section 9.2
Listing 9.6 CheckBox in MainPage.xaml
<CheckBox IsChecked="{Binding Done, Mode=TwoWay}"
VerticalOptions="Center"
HorizontalOptions="Center"
Grid.Column="0"
Grid.Row="0"> #1
<CheckBox.Behaviors>
<behaviors:EventToCommandBehavior #2
EventName="CheckedChanged" #3
Command="{Binding Source={x:Reference PageTodo}, #4
Path=BindingContext.CompleteTodoCommand}" #5
CommandParameter="{Binding .}"/> #6
</CheckBox.Behaviors>
</CheckBox>
This XAML example shows the behavior attached directly to a CheckBox, connecting its CheckedChanged event to a ViewModel command rather than requiring a custom control subclass. section 9.2
For a genre-selection popup, bind an ObservableCollection of genres to a CollectionView with multiple selection. Track whether selection changed, update each genre’s Selected state, and close the popup with that result when the user confirms or taps outside it. section 6.2.2
