【问题标题】:WPF Multiple dictionaries for single controlWPF 用于单个控件的多个字典
【发布时间】:2014-04-03 14:43:27
【问题描述】:

我有一个按钮控件,我已关联一个字典,在该字典中我更改了按钮控件的控件模板,但现在在不同的屏幕上我不想在我想更改的按钮控件上应用该字典模板。这件事怎么可能实现?

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" >

   <Style TargetType="{x:Type Button}">
    Some control template changes

   </Style>

谢谢

【问题讨论】:

    标签: wpf wpf-controls resourcedictionary


    【解决方案1】:

    看起来您为按钮定义了一种样式。您希望将此样式应用于 Screen1 上的按钮。

    但是对于 screen2 中的按钮,您不想应用相同的样式。

    为所有按钮应用样式,这取决于资源字典的范围。如果其应用范围,该样式将应用于所有屏幕中的所有按钮。

    <Application.Resources> <ResourceDictionary Source="MyResourceDictionary.xaml" /> </Application.Resources>

    如果您想要特定于屏幕 1 的样式,请仅在屏幕 1 用户控件中创建此字典,以便范围仅适用于该用户控件,例如...

    <Usercontrol.Resources> <ResourceDictionary Source="MyResourceDictionary.xaml" /> <userControl.Resources>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多