如何在 WPF 中删除(避免)焦点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20947479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove (avoid) focus in WPF
提问by Rudresh Bhatt
I want to avoid focus coming on wpf Gridfor that I have tried:
我想避免将注意力集中在 wpf 上Grid,因为我已经尝试过:
<Grid Focusable="False" />
but it is not working. I also tried with:
但它不起作用。我也试过:
<Grid x:Name="Grid" Focusable="False" FocusVisualStyle="{x:Null}" />
but I again failed. How can I avoid focus coming on Grid?
但我又失败了。我怎样才能避免注意力集中Grid?
回答by Anatoliy Nikolaev
ContentControlhas a default Focusable="True", because Controlbase class overrides the metadata of the Focusable property and sets its default to true - MSDN.
ContentControl有一个默认值Focusable="True",因为Control基类覆盖了 Focusable 属性的元数据并将其默认值设置为 true- MSDN。
Just set the value to false:
只需将值设置为false:
<ContentControl Focusable="False" />
To keep track of where it comes focus, Snoopa wonderful program. In it, you can find the source of focus.
跟踪它的焦点,Snoop一个很棒的程序。在其中,您可以找到焦点的来源。

