【发布时间】:2012-03-09 13:48:30
【问题描述】:
我需要从界面中的每个控件中删除选定的状态(效果)或任何它被调用的内容。你知道黑色虚线...
有哪些方法可以做到?
附:完全自定义的 XAML 页面使用 30MB RAM 是否正常?
提前致谢。
【问题讨论】:
-
你的附言应该作为一个单独的问题发布。
我需要从界面中的每个控件中删除选定的状态(效果)或任何它被调用的内容。你知道黑色虚线...
有哪些方法可以做到?
附:完全自定义的 XAML 页面使用 30MB RAM 是否正常?
提前致谢。
【问题讨论】:
即由关联控件的FocusVisualStyle 控制。不幸的是,您不能使用单个 Style 或设置为所有控件全局禁用它。相反,您必须为每种控件类型单独关闭它。
例如,您可以在 Application.Resources 中包含以下样式,以便为指定的控件关闭它:
<Style TargetType="Button">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<Style TargetType="RepeatButton">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<Style TargetType="ToggleButton">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<Style TargetType="TreeViewItem">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<!-- ETC -->
但请记住,如果您在任何控件上使用 Style 属性,或者如果您定义了任何其他隐式样式,那么这些将阻止应用上述样式。
或者正如 Rachel 指出的那样,你可以这样做:
<Style x:Key="FrameworkElementStyleKey" TargetType="FrameworkElement">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
<Style TargetType="Button" BasedOn="{StaticResource FrameworkElementStyleKey}" />
<Style TargetType="RepeatButton" BasedOn="{StaticResource FrameworkElementStyleKey}" />
<Style TargetType="ToggleButton" BasedOn="{StaticResource FrameworkElementStyleKey}" />
<Style TargetType="TreeViewItem" BasedOn="{StaticResource FrameworkElementStyleKey}" />
<!-- ETC -->
从功能上来说,上述两种方法的效果是一样的。
【讨论】:
FocusVisualStyle 的FrameworkElement 创建单个基本样式,然后使用从基本样式继承的单行控件样式来进一步简化样式。有一个很好的例子here