4
当按下左/右键时,我想阻止我的程序改变聚焦的元素,因为当按下这些按钮时我需要其他的东西来发生。现在,当点击某个按钮加载所有内容后,按下按键时,焦点将设置为该按钮旁边的组合框,从而防止按键执行任何操作,而不是更改组合框的选定索引。按左/右键时防止焦点变化
我有当一个键被按下车窗上此代码:
private void Window_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (!PostTypeComboBox.IsFocused && !PredefinedSubsComboBox.IsFocused && !SortComboBox.IsFocused)
{
switch (e.Key)
{
case System.Windows.Input.Key.Left:
e.Handled = false;
ViewModel.GoToPreviousPost();
PreviousImageButton.Focus();
break;
case System.Windows.Input.Key.Right:
e.Handled = false;
ViewModel.GoToNextPost();
NextImageButton.Focus();
break;
default:
break;
}
}
}
我已经试过与不switch语句中的以下行:
e.handled = False;
PreviousImageButton.Focus();
NextImageButton.Focus();
但没有我做似乎防止焦点改变,_ImageButton.Focus()不改变焦点,它仍然返回到组合框。
有你的TabStop属性,在全乱? – Kcvin
我想你需要设置e.Handled = true; – Umesh
SystemOnline,解决了这个问题!谢谢。不知道为什么我在发布之前没有尝试过。 – Mohawk