I've been using i:Interaction.Triggers and an EventToCommand implementation to handle certain control events in my VM.
<DataGrid ...>
<i:Interaction.Triggers>
<i:EventTrigger EventName="AutoGeneratingColumn">
<ui:EventToCommand Command="{Binding Path=DataContext.AutoGeneratingColumnCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
PassEventArgsToCommand="True" />
All worked fine. Then I needed to have multiple DataGrids, so I created a ItemsControl template that has the DataGrid with the interaction triggers. I noticed in this case, the triggers are not working.
Is this a known issue? I debugged the EventToCommand class and it is calling the Attach member, but it never calls the Invoke.
The ItemsControl looks like:
<ItemsControl>
<ItemsControl.ItemsTemplate>
<DataGrid ...>
<i:Interaction.Triggers>
<i:EventTrigger EventName="AutoGeneratingColumn">
<ui:EventToCommand Command="{Binding Path=DataContext.AutoGeneratingColumnCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
PassEventArgsToCommand="True" />
Any ideas? Am I doing something wrong?
EDIT:
<ItemsControl Grid.Row="2" ItemsSource="{Binding StoredProcedureResults}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DataGrid EnableColumnVirtualization="True" EnableRowVirtualization="True" SelectionMode="Extended" SelectionUnit="CellOrRowHeader"
CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" BorderThickness="0,0,0,0" ItemsSource="{Binding}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="AutoGeneratingColumn">
<UI:EventToCommand Command="{Binding Path=DataContext.AutoGeneratingColumnCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
PassEventArgsToCommand="True" />
</i:EventTrigger>
<i:EventTrigger EventName="LoadingRow">
<UI:EventToCommand Command="{Binding Path=DataContext.LoadingRowCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"
PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGrid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>