Wpf UserControl使用 KeyBinding,失效问题

Posted lonelyxmas

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wpf UserControl使用 KeyBinding,失效问题相关的知识,希望对你有一定的参考价值。

原文:Wpf UserControl使用 KeyBinding,失效问题

我的问题根源是UserControl未获取相应焦点,在UserControl后台添加如下

 public AccountDetailView()
        {
            InitializeComponent();
            this.IsEnabledChanged +=new DependencyPropertyChangedEventHandler(AccountDetailView_IsEnabledChanged);  
        }



        private void control_detail_Loaded(object sender, RoutedEventArgs e)
        {
            tb_detail.Focusable = true;
            Keyboard.Focus(this);
        }




        void AccountDetailView_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (!Convert.ToBoolean(e.NewValue)) return;
            this.Focusable = true;
            Keyboard.Focus(this);
        }

以上是关于Wpf UserControl使用 KeyBinding,失效问题的主要内容,如果未能解决你的问题,请参考以下文章

WPF 导航和销毁当前 UserControl

UserControl在wpf中使用父元素?

WPF 用户控件不呈现。 UserControl 使用 DataTemplates 实例化

WPF usercontrol mvvm

wpf mvvm使用问题集锦

WPF 使用UserControl来切换界面