【发布时间】:2014-04-04 20:18:59
【问题描述】:
是否可以在后面的代码中执行以下操作(在数据网格中设置标题双击事件)?如果是,如何?我搜索的任何内容都没有显示可以访问数据网格标题的样式!
<DataGrid ...>
<DataGrid.Resources>
<Style TargetType="DataGridColumnHeader">
<EventSetter Event="MouseDoubleClick" Handler="OnTableDoubleClick" />
</Style>
</DataGrid.Resources>
...
非常感谢。
编辑
经过其他尝试,我也在从DataGrid派生的CustomDataGrid类的构造函数中尝试了这个:
Style _style = new Style(typeof(DataGridColumnHeader));
_style.BasedOn = Application.Current.Resources["DataGridColumnHeaderStyle"] as Style;
_style.Setters.Add(new EventSetter(MouseDoubleClickEvent, new MouseButtonEventHandler(OnTableDoubleClick)));
this.ColumnHeaderStyle = _style;
如果我很好理解我所做的这应该将双击事件添加到标题样式中,但实际上它什么也不做,这意味着处理程序不会在运行时调用。
【问题讨论】:
标签: c# wpf events datagrid styles