Wpf 如何判断所选数据单元是数据网格的头还是部分

Wpf 如何判断所选数据单元是数据网格的头还是部分,wpf,datagrid,xceed-datagrid,Wpf,Datagrid,Xceed Datagrid,我的WPF应用程序中有一个Xceed datagrid,每个单元格都有一个OnClick事件。但是,我希望能够根据单元格是否为列标题或单元格是否仅存储数据来处理该事件。如果有人在这方面有任何建议或经验,我将不胜感激。您如何安排活动?可以使用不同的样式和事件将datagridrow、datacell、columnheader单元格作为目标。但是,您必须注意,有几个事件是由Xceed控件处理的,有时还必须使用事件的预览版本 <Window.Resources> <Style Ta

我的WPF应用程序中有一个Xceed datagrid,每个单元格都有一个
OnClick
事件。但是,我希望能够根据单元格是否为列标题或单元格是否仅存储数据来处理该事件。如果有人在这方面有任何建议或经验,我将不胜感激。

您如何安排活动?可以使用不同的样式和事件将datagridrow、datacell、columnheader单元格作为目标。但是,您必须注意,有几个事件是由Xceed控件处理的,有时还必须使用事件的预览版本


<Window.Resources>
<Style TargetType="xcdg:DataCell">
    <EventSetter Event="PreviewMouseLeftButtonDown" Handler="dataCellMouseLeftButtonDown"/>
</Style>
<Style TargetType="xcdg:ColumnManagerCell">
    <EventSetter Event="PreviewMouseLeftButtonDown" Handler="colManagerMouseLeftButtonDown"/>
</Style>
</Window.Resources>

<xcdg:DataGridControl ItemsSource="{Binding}"/>


 private void dataCellMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
    MessageBox.Show("Left mouse button down on Cell");
 }

 private void colManagerMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
   MessageBox.Show("Left mouse button down on Column manager cell");
 }
私有void数据单元mouseleftbuttondown(对象发送方,MouseButtonEventArgs e) { Show(“鼠标左键按下单元格”); } 私有void colManagerMouseLeftButtonDown(对象发送器,鼠标按钮Ventargs e) { Show(“在列管理器单元格上按下鼠标左键”); }

注意如果将预览事件替换为正常事件,则数据网格不会触发这些事件。它将自行处理这些鼠标事件(分别启动内联编辑和排序)。

我在网格初始化时设置事件。AddHandler(Cell.GotFocusEvent,新RoutedEventHandler(Cell_GotFocus));谢谢你帮我解决这个问题。我一切都运转得很好。