I have datagrid. One column is with button:
<DataGrid x:Name="WordsDataGrid" Grid.Column="0" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
AutoGenerateColumns="False" CellEditEnding="WordsDataGrid_CellEditEnding">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="X" Width="10" Binding="{Binding Status}"/>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Visibility="Visible" Height="16" Width="16" Click="Update_Click">
<Button.Content>
<Image x:Name="KeyName" Source="Resources/update.png" />
</Button.Content>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
I have other columns with textbox create dynamic in c#.
I want to change image for my button when catch event:
private void WordsDataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
var column = e.Column.DisplayIndex;
var row = e.Row.GetIndex();
}
I know row and column but I dont know how to take my button from WordsDataGrid to do:
button.Content = new Image
{
Source = new BitmapImage(new Uri(@"/Resources/toupdate.png", UriKind.Relative))
};
Edit:
I add
Source="{Binding ImageSource}" />
public string ImageSource { get; set; } = @"\Resources\update.png";
First to xaml, secound to object, and I change string.