79790453

Date: 2025-10-14 17:32:57
Score: 0.5
Natty:
Report link

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:

https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/behaviors/event-to-command-behavior#using-the-eventtocommandbehavior

Reasons:
  • Whitelisted phrase (-1): this worked for me
  • Whitelisted phrase (-1): worked for me
  • RegEx Blacklisted phrase (3): not working for me
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Rodas PT