【发布时间】:2014-09-03 10:16:32
【问题描述】:
我有带有上下文菜单的数据网格。它以编程方式初始化:
contextMenu = new ContextMenu();
foreach (var col in this.Columns)
{
var checkBox = new MenuItem()
{
Header = col.Header
};
Binding myBinding = new Binding("Visibility");
myBinding.Mode = BindingMode.TwoWay;
myBinding.Converter = new IsCheckedToVisibilityConverter();
checkBox.DataContext = col;
checkBox.SetBinding(MenuItem.IsCheckedProperty, myBinding);
checkBox.Click += checkBox_Click;
checkBox.Checked += checkBox_Checked;
checkBox.Unchecked += checkBox_Unchecked;
contextMenu.Items.Add(checkBox);
}
效果很好,但我想在选中\取消选中菜单项后保持打开上下文菜单。有什么想法吗?
【问题讨论】:
标签: c# wpf contextmenu