Ayappan A

Ayappan A

  • 1.6k
  • 98
  • 12.7k

MVVM Binding for Datagrid column inside itemscontrol

Nov 29 2019 3:24 AM
How to Bind Button command event for DataGrid  inside ItemsControl.
 
 I want
1.CellCommand evet for CellEditEnding 
2.AddNew command for button
 
<ItemsControl ItemsSource="{Binding ObjCollection}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Height="200">
<Label Content="{Binding Name}"/>
<DataGrid Name="dGrid" VerticalScrollBarVisibility="Auto" MaxHeight="150" ItemsSource="{Binding Dt}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="CellEditEnding">
<i:InvokeCommandAction Command="{Binding CellCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<DataGrid.Columns>
<DataGridTemplateColumn DisplayIndex="15">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Add New" Command="{Binding Path=DataContext.AddNew, RelativeSource= {RelativeSource FindAncestor,
AncestorType={x:Type DataGrid}
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
 

Answers (5)