For me the suggestion shared were not working for me.
Net 9.0 SDK 9.0.305
So this worked for me.
I define the Behavior on the DatePicker using the current context of the page:
<DatePicker Date="{Binding Path=FieldDate, Mode=TwoWay}">
<DatePicker.Behaviors>
<toolkit:EventToCommandBehavior BindingContext="{Binding Path=BindingContext, Source={x:Reference Page}, x:DataType=ContentPage}"
EventName="DateSelected" Command="{Binding DatePickedCommand}"/>
</DatePicker.Behaviors>
</DatePicker>
Then on my view model:
[ObservableProperty] private DateTime fieldDate;
[RelayCommand]
private void DatePicked()
{
if (FieldDate > DateTime.Now)
//Todo
}
Don't forget the give a name of your content page for the Reference to work: x:Name="Page"
References: