【问题标题】:Generic.xaml - Referencing stylesGeneric.xaml - 引用样式
【发布时间】:2011-04-01 23:30:34
【问题描述】:

如果我在 Generic.xaml 中有一个样式,并且我想在 SAME Generic.xaml 文件中引用一个样式,为什么它不起作用?

<Style TargetType="{x:Type w:SomeControlIWantToStyle}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type w:SomeControlIWantToStyle}">
                    ...
                    <TextBlock Text="{DynamicResource SomeStyle}" />

                    ...

<Style x:Key="SomeStyle" ... />

我无法从 ControlTemplate 中引用“SomeStyle”!

有什么想法吗?

【问题讨论】:

    标签: c# wpf xaml generic.xaml


    【解决方案1】:

    请把

    <Style x:Key="SomeStyle" ... /> 
    

    在此样式之上的样式

    <Style TargetType="{x:Type w:SomeControlIWantToStyle}"> 
        <Setter Property="Template"> 
            <Setter.Value> 
                <ControlTemplate TargetType="{x:Type w:SomeControlIWantToStyle}"> 
                    ... 
                    <TextBlock Text="{DynamicResource SomeStyle}" /> 
    
                    ... 
    

    只需保持层次结构。如果要调用样式,只需在调用样式上方声明样式即可。

    【讨论】:

      猜你喜欢
      • 2012-06-24
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 2016-10-16
      • 1970-01-01
      • 2016-08-09
      相关资源
      最近更新 更多