【问题标题】:How to apply multy style to single control in wpf? [duplicate]如何将多种样式应用于wpf中的单个控件? [复制]
【发布时间】:2012-07-28 20:50:54
【问题描述】:

可能重复:
How to apply multiple styles in WPF

<Window.Resources>   
    <Style TargetType="Button" x:Key="style_1">
        <Setter Property="Foreground" Value="Green" />
    </Style>
    <Style TargetType="Button" x:Key="style_2">
        <Setter Property="Background" Value="Blue" />
    </Style>    
</Window.Resources>


    <Button x:Name="btn_1" Content="Button" HorizontalAlignment="Left" Height="40" Margin="153,95,0,0" VerticalAlignment="Top" Width="89" Style="{StaticResource style_1}" Click="Button_Click" />
    <Button x:Name="btn_2" Content="Button" Height="40" Margin="281,95,262,0" VerticalAlignment="Top" Style="{StaticResource style_2}"/>

现在我想将 style_1 和 style_2 应用到 btn_1 我应该怎么做。

【问题讨论】:

    标签: wpf styles


    【解决方案1】:

    您不能将两种样式应用于 XAML 中的单个控件。

    你可以做的是让 style_2 通过指定从 style_1 继承

    <Style TargetType="Button" x:Key="style_2" BasedOn="{StaticResource style_1}"> 
        <Setter Property="Background" Value="Blue" />
    </Style>
    

    然后只使用 style_2。

    【讨论】:

      猜你喜欢
      • 2012-08-20
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      • 2016-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多