【问题标题】:Getting the xaml name of a control using a MouseMove event使用 MouseMove 事件获取控件的 xaml 名称
【发布时间】:2016-09-01 05:33:04
【问题描述】:

我有 2 个 DataGrid。

 <DataGrid x:Name="dataGrid1"  />


 <DataGrid x:Name="dataGrid2"  />

是否可以从 MouseMove 事件中获取我当前所在的 DataGrid 的 xaml 名称?

谢谢!

编辑: 我正在使用第三方源 - Syncfusion 来创建 SfDataGrid。

【问题讨论】:

    标签: wpf xaml datagrid mousemove


    【解决方案1】:

    试试这个:

    ABC.xaml

    <SfDataGrid x:Name="dataGrid1" MouseEnter="DG_OnMouseEnter" />
    <SfDataGrid x:Name="dataGrid2" MouseEnter="DG_OnMouseEnter" />
    

    ABC.xaml.cs [代码隐藏]

    private void DG_OnMouseEnter(object sender, MouseEventArgs e)
    {
        Debug.WriteLine(((FrameworkElement) sender).Name);
        if (sender is SfDataGrid) e.Handled = true; //prevent event-execution of childs
    }
    

    【讨论】:

    • 感谢您的快速回复。我没有提到,但我正在使用第三方来源 - 我正在使用 Syncfusion 创建一个 SfDataGrid。解决您的建议的任何尝试均未成功。
    • @dov:我更新了我的答案。你能检查一下 DG_OnMouseMove 是否被调用(使用断点)...你也可以使用 Event MouseEnter...
    • 我尝试更新我的代码,我得到“PART_VisualContainer”作为名称(由于某种原因这是正确的)。
    • @dov:更新了我的答案
    猜你喜欢
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多