WPF DataGrid - 将按钮添加到每一行的末尾 [英] WPF DataGrid - add button to end of every row
本文介绍了WPF DataGrid - 将按钮添加到每一行的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在数据网格的每一行的末尾添加一个按钮。我找到了以下xaml,但是它将按钮添加到开始。任何人都知道如何在所有的数据绑定列之后添加它?
I'd like to add a button to the end of every row of my datagrid. I've found the following xaml but it adds the button to the start. Anyone know how I can add it after all the databound columns?
这个按钮添加到开始而不是结束:
This adds the button to the start instead of the end:
<DataGrid Background ="Black" ItemsSource="{Binding PriceList}">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button>My button</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
非常感谢提前
推荐答案
您必须手动添加列。
关闭列的自动生成,并按照您要的顺序添加列,包括列表末尾的额外列:
Turn off the autogeneration of the columns and add them in the order you want them, including your extra column at the end of the list:
<DataGrid Background ="Black"
ItemsSource="{Binding PriceList}"
AutoGenerateColumns="False">
<DataGrid.Columns>
<!-- Add your normal columns here -->
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button>My button</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
这篇关于WPF DataGrid - 将按钮添加到每一行的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文