[英]Wpf window Showdialog not getting focus
I am calling a method using delegate to show a color window but that window not getting focus,It is working fine with mouse but for touch it requires one extra click to get focus.我正在调用一种使用委托的方法来显示颜色 window 但是 window 没有获得焦点,它在鼠标上工作正常,但对于触摸它需要额外单击才能获得焦点。
ColorPickerWindow colorPicker = new ColorPickerWindow ();
colorPicker.Owner = this;
colorPicker.ShowInTaskbar = false;
colorPicker.SetColor(MenuColor);
colorPicker.ShowDialog();
Just call Element.Focus()
on the element you want to focus.只需在要聚焦的元素上调用
Element.Focus()
即可。
If you mean bring focus to the window try calling window.Activate()
如果你的意思是把焦点放在 window 尝试调用
window.Activate()
Source: WPF Window set Focus来源: WPF Window 集焦点
I found that window.ShowDialog()
fails to get window focus (pops under) when .ShowDialog()
is called on a thread other than the UI thread for your main window.我发现当在主 window 的 UI 线程以外的线程上调用
.ShowDialog()
时, window.ShowDialog()
无法获得 window 焦点(弹出)。
For me the problem went away when I made sure to .Invoke()
my .ShowDialog()
on the correct UI thread.对我来说,当我确保在正确的 UI 线程上
.Invoke()
我的.ShowDialog()
时,问题就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.