-
Notifications
You must be signed in to change notification settings - Fork 22
DataGrid 添加Button
L edited this page May 13, 2020
·
2 revisions
<DataGrid ItemsSource="{Binding }" AutoGenerateColumns="False" CanUserAddRows="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="操作" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button Content="删除" Tag="{Binding 需要的参数}" Click="Delete_Click" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
private void Delete_Click(object sender, RoutedEventArgs e)
{
var num = (sender as Button).Tag.ToString();
//从数据集中删除目标数据
}
DataGridBindMultiData.xaml
DataGridBindMultiData.xaml.cs
WPF DataGridTemplateColumn添加按钮
WPF中DataGrid控件内Button的Command和CommandParameter的绑定