【问题标题】:Prevent Silverlight DataGrid from Processing Enter Key防止 Silverlight DataGrid 处理 Enter 键
【发布时间】:2011-11-17 23:55:00
【问题描述】:

我在 Silverlight 应用程序中有一个数据网格。单击第一行,然后按 Enter 键会使选择移动到下一行。我不希望这种行为 - Enter 键在此屏幕上用于完全不同的目的。

我意识到这是编辑框架的一部分,但我需要一种方法来关闭它。我尝试将 IsReadOnly 设置为 True(即使该控件在技术上不是只读的),但没有任何效果。

我附加到 datagrid KeyDown 事件,但按下 Enter 键时不会调用它。它适用于其他键。

我被难住了。感谢您的帮助。

【问题讨论】:

    标签: silverlight xaml datagrid


    【解决方案1】:

    是的,这很烦人。

    据我所知,唯一的选择是创建您自己的继承自 DataGrid 的控件,并在将事件传递到基础之前执行所需的操作。

    public class NewDataGrid : DataGrid 
    {     
        protected override void OnKeyDown(KeyEventArgs e)     
        {         
            if (e.Key == Key.Enter)         
            {
                //do what is needed here             
                e.Handled = true;         
            }         
            base.OnKeyDown(e);     
        } 
    } 
    

    【讨论】:

      猜你喜欢
      • 2013-01-12
      • 2010-10-28
      • 1970-01-01
      • 2011-08-03
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多