Hi @Bhuwan , Sorry to bother you! I'm posting this answer to explain why your previous code didn't work and also help others who might encounter the same issue.
In the first snippet, you're binding OnChanged in SelectedIndexChanged:
<Picker
…
SelectedIndexChanged="{Binding OnChanged}" />
In XAML, event attributes (like SelectedIndexChanged="...") expect a code‑behind method name, not a data binding. You can’t bind an event to a ViewModel method.
In the second snippet, you're using EventToCommandBehavior:
<Picker x:Name="pickerPatrolType" …>
<Picker.Behaviors>
<toolkit:EventToCommandBehavior
EventName="SelectedIndexChanged"
Command="{Binding CheckPatrolTypeSelectedCommand}" />
</Picker.Behaviors>
</Picker>
Starting with CommunityToolkit.Maui v10, behaviors do not inherit the parent control’s BindingContext. Without explicitly setting it, the Command binding can’t resolve—so your command never fires.
To fix this issue, set the behavior’s BindingContext to the control’s BindingContext:
<toolkit:EventToCommandBehavior
EventName="SelectedIndexChanged"
BindingContext="{Binding Source={x:Reference pickerPatrolType}, Path=BindingContext}"
Command="{Binding CheckPatrolTypeSelectedCommand}" />
Here is a full example of how to implement a logic trigger when a Picker selection changes using MVVM toolkit.
- View:
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
<Picker x:Name="pickerPatrolType"
ItemsSource="{Binding PicPatrolTypes}"
ItemDisplayBinding="{Binding GUIValue}"
SelectedItem="{Binding PicPatrolTypeSelectedItem}"
SelectedIndex="{Binding PicPatrolTypeIndex, Mode=TwoWay}">
<Picker.Behaviors>
<toolkit:EventToCommandBehavior
EventName="SelectedIndexChanged"
BindingContext="{Binding Source={x:Reference pickerPatrolType}, Path=BindingContext}"
Command="{Binding PatrolTypeChangedCommand}"
CommandParameter="{Binding Source={x:Reference pickerPatrolType}, Path=SelectedItem}" />
</Picker.Behaviors>
</Picker>
</ContentPage>
- ViewModel
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
public partial class MyViewModel : ObservableObject
{
[ObservableProperty] private int picPatrolTypeIndex = -1;
[ObservableProperty] private object? picPatrolTypeSelectedItem;
[RelayCommand]
private void PatrolTypeChanged(object? selectedItem)
{
if (PicPatrolTypeIndex != -1)
{
// do stuff (e.g., update other bound collections)
}
else
{
// do other stuff
}
}
}