I am trying to trigger an event when a ComboBoxColumn
selection in a DataGrid
changes. But I cannot get the binding to work. When I debug DataContext
is shown as null
. No matter what I try I can't seem to locate the DataContext
. Oddly enough TestCommand
is recognised by intellisence. xaml is as follows:
<CollectionViewSource x:Key="GridViewSource" Source="{Binding vmCollection}"/>
<CollectionViewSource x:Key="CurrenciesList" Source="{Binding Currencies}"/>
<DataGrid x:Name="MyGrid"
ItemsSource="{Binding Source={StaticResource GridViewSource}}">
<DataGridComboBoxColumn Header="Currency"
ItemsSource="{Binding Source={StaticResource CurrenciesList}}"
DisplayMemberPath="Name"
SelectedValuePath="Code"
SelectedValueBinding="{Binding CurrencyCode}">
<behaviors:Interaction.Triggers>
<behaviors:EventTrigger>
<behaviors:InvokeCommandAction EventName="SelectionChanged"
'Issue is here
Command="{Binding TestCommand}"/>
</behaviors:EventTrigger>
</behaviors:Interaction.Triggers>
</DataGridComboBoxColumn>
</DataGrid>
When I try the below on a button in the datagrid, everything works as expected. But not if I use them for the Combobox column event.
Command="{Binding DataContext.TestCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}"
Command="{Binding DataContext.TestCommand, ElementName=MyGrid}"