【问题标题】:Removing Selected State of all templates (Global Style)删除所有模板的选定状态(全局样式)
【发布时间】:2012-03-09 13:48:30
【问题描述】:

我需要从界面中的每个控件中删除选定的状态(效果)或任何它被调用的内容。你知道黑色虚线...

有哪些方法可以做到?

附:完全自定义的 XAML 页面使用 30MB RAM 是否正常?

提前致谢。

【问题讨论】:

  • 你的附言应该作为一个单独的问题发布。

标签: wpf xaml select state


【解决方案1】:

即由关联控件的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 -->

从功能上来说,上述两种方法的效果是一样的。

【讨论】:

  • 您可以通过为包含FocusVisualStyleFrameworkElement 创建单个基本样式,然后使用从基本样式继承的单行控件样式来进一步简化样式。有一个很好的例子here
猜你喜欢
  • 2012-03-06
  • 2010-12-28
  • 2012-11-25
  • 2013-01-05
  • 1970-01-01
  • 1970-01-01
  • 2015-11-24
  • 1970-01-01
相关资源
最近更新 更多