Search code examples
c#wpftelerik

Invoking LostFocus event from RadDatePicker inside a RadGridView in WPF


I have a RadGridView inside which I have a RadDatePicker I want to fire a command on any change with that date.

I am trying to achieve that through

<telerik:GridViewColumn Header="Date of Travel" >
    <telerik:GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=FlightDetails.FltDate, StringFormat=dd-MMM-yyyy}">
            </TextBlock>
        </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>
    <telerik:GridViewColumn.CellEditTemplate>
        <DataTemplate>
            <telerikControls:RadDatePicker SelectedDate="{Binding Path=FlightDetails.FltDate,UpdateSourceTrigger=LostFocus,Mode=TwoWay, StringFormat=dd-MMM-yyyy}" DisplayFormat="Short" Culture="en-AU">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="LostFocus">
                        <i:InvokeCommandAction Command="{Binding DataContext.DateOfFlightCommand, RelativeSource={RelativeSource AncestorType={x:Type baseview:QRUserControl}}}" 
                                               CommandParameter="{Binding}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </telerikControls:RadDatePicker>
        </DataTemplate>
    </telerik:GridViewColumn.CellEditTemplate>
</telerik:GridViewColumn>

Nothing is triggered.


Solution

  • Your binding is probably invalid. If the DateOfFlightCommand property is defined in the view model of the parent window, you should specify Window as the the AncestorType:

    <i:InvokeCommandAction Command="{Binding DataContext.DateOfFlightCommand, 
                                RelativeSource={RelativeSource AncestorType={x:Type Window}}}" CommandParameter="{Binding}" />