WPF 中如何使得DataGrid的Column有鼠标点击相应
2014-04-24 19:16
543 查看
http://stackoverflow.com/questions/5895803/how-do-i-capture-click-events-on-a-datagrid-column-headers
The headers are just buttons. Like any button, you can register to the Clickevent to capture those clicks. Just set a style targeting DataGridColumnHeaderand add a Clickevent handler. Then within the handler, you have access to the header directly via the sender. You could then get the Columnassociated with that header and other information associated with it. <DataGrid> <DataGrid.Resources> <Style TargetType="DataGridColumnHeader"> <EventSetter Event="Click" Handler="columnHeader_Click" /> </Style> </DataGrid.Resources> </DataGrid> Then in the code: private void columnHeader_Click(object sender, RoutedEventArgs e) { var columnHeader = sender as DataGridColumnHeader; if (columnHeader != null) { // do stuff } } Looking further into the DataGrid, I noticed that there's a ColumnHeaderStyleproperty. I think it would be a better idea to apply the style through this property instead. <DataGrid> <DataGrid.ColumnHeaderStyle> <Style TargetType="DataGridColumnHeader"> <EventSetter Event="Click" Handler="columnHeader_Click" /> </Style> </DataGrid.ColumnHeaderStyle> </DataGrid>
| |||||||||||||||||||||||||||||||
|
相关文章推荐
- 各位大虾请帮忙 如何实现用鼠标点击datagrid的某一行然后用js获得选中行的所有值
- wpf——datagrid中如何获取DataGridTextColumn等某行某列的值
- WPF 实现DataGrid行鼠标经过、点击时的背景、文字、行高等样式
- WPF中的DataGridTemplateColumn实现点击列标题排序
- WPF DataGrid DataGridTemplateColumn 列头checkbox如何在代码中取消选择
- FB4 AS3 如何获取advancedDataGrid中鼠标点击checkbox列的行号
- WPF 实现DataGrid行鼠标经过、点击时的背景、文字、行高等样式
- js 如何判断鼠标点击事件还是js代码调用
- 如何相应状态栏的鼠标动作
- 如何实现点击按钮后,隐藏datagrid的某一列
- wpf mvvm datagrid DataGridTemplateColumn的绑定无效的可能原因之一!
- WPF DataGridComboBoxColumn的使用方法
- WPF使用DataGridComboBoxColumn完成绑定
- WPF DataGridCheckBoxColumn列不更新问题方案
- java中如何弹出子对话框,使得点击其他区域无效
- 用户控件包含一个搜索功能,但是在调用页面中按回车时无法直接提交这个表单,只有鼠标点击才提交,如何解决?
- 鼠标键为什么按小键盘5以及+的时候却有时变成了右键点击,如何改为左键点击
- 我想在datagrid中选择若干记录,再点击添加按钮,给别一个ACCESS表添加选择的记录,在VB中如何实现?
- js鼠标事件解析——如何用js实现一个拖动但是不触发其点击事件
- WPF透明控件的鼠标点击穿透