【发布时间】:2015-06-19 20:33:51
【问题描述】:
我正在尝试将个性化和单独的 ContextMenus 添加到项目中的每个列标题,以便当用户右键单击标题时,将出现与该标题相关的复选框菜单,允许他们过滤数据.
有几个问题:我正在处理的项目需要为 .NET 4.0 开发,因此我无法访问在 .NET 4.5 中引入的 DataGridColumnHeader 类。此外,所有这些都需要以编程方式完成,不允许使用 XML,因为所有列数据都是在运行时确定的。
我找到了一个similar Stack question,它是使用 XML 完成的,并且我已经成功地在 XML 中复制了它,但我是 WPF 新手,无法以编程方式复制它。
我在下面粘贴了一些 C# 代码,我认为应该进行设置。
/// <summary>
/// Function that adds all of the columns for the default setup
/// </summary>
public void MakeAllColumns()
{
for (int i = 0; i < AllColumnDisplayNames.Length; i++)
{
DataGridTextColumn col = new DataGridTextColumn();
col.Header = AllColumnDisplayNames[i];
col.Binding = new Binding(AllColumnBindings[i]);
canGrid.Columns.Add(col);
// code for addding context menus will most likely go here
}
}
【问题讨论】:
标签: c# .net wpf datagrid wpfdatagrid