2012-07-31 21 views
0

可能重复:
How to apply multiple styles in WPF如何在wpf中将multy风格应用于单一控件?

<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我应该做到这一点。

回答

0

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

你可以做什么,是让style_2通过指定

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

从style_1继承,然后只使用style_2。

相关问题