Sephystos
Sephystos

Reputation: 69

Fire Command or Trigger from DatePicker

as mentioned in the title, I would like to create a trigger on a datepicker, or something equivalent. Here is the situation:

    <DatePicker SelectedDate="{BindingDateDebut}"/>
    <DatePicker SelectedDate="{Binding DateEnd}"/>

No worries about the binding of dates. Now, I'd like when I change my date, it triggers a Command:

            LoadMatrice = new RelayCommand(async () =>
        {
            await GetParametresMatrice();
        });

To access the "GetParametresMatrice()" method for example.

I could add the method in the "DateStart" and "DateEnd" set of course, but sometimes both dates change at the same time (during initialization for example) and without "await", my tasks are done at the same time and the output the code gives bad results.

I try with something like :

            <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                <i:InvokeCommandAction Command="{Binding LoadMatrice}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>

But it doesn't fire. Any tips ?

Thank you in advance!

Upvotes: 1

Views: 528

Answers (1)

mm8
mm8

Reputation: 169200

The DatePicker has no SelectionChanged event but it has a SelectedDateChanged event that you can try to handle:

<i:EventTrigger EventName="SelectedDateChanged">

Upvotes: 1

Related Questions