重用代码

    1. <Window.Resources>
    2. <Style x:Key="defaultStyle" TargetType="Button">
    3. <Setter Property="FontSize" Value="20"/>
    4. <Setter Property="Background" Value="Red"/>
    5. <Setter Property="Content" Value="Hello"/>
    6. <Setter Property="Width" Value="60"/>
    7. <Setter Property="Height" Value="40"/>
    8. </Style>
    9. </Window.Resources>
    10. <Grid ShowGridLines="True">
    11. <StackPanel>
    12. <Button Style="{StaticResource defaultStyle}"/>
    13. <Button Style="{StaticResource defaultStyle}"/>
    14. <Button Style="{StaticResource defaultStyle}"/>
    15. </StackPanel>
    16. </Grid>

    样式继承少用BasedOn=”{StaticResource default}”

     <Window.Resources>
            <Style x:Key="defaultStyle" TargetType="Button">
                <Setter Property="FontSize" Value="20"/>
                <Setter Property="Background"  Value="Red"/>
                <Setter Property="Content" Value="Hello"/>
                <Setter Property="Width" Value="60"/>
                <Setter Property="Height" Value="40"/>
            </Style>
    
            <Style x:Key="SecondStyle" TargetType="Button"
                   BasedOn="{StaticResource defaultStyle}">
                <Setter Property="IsEnabled" Value="False"/>
            </Style>
        </Window.Resources>
        <Grid ShowGridLines="True">
            <StackPanel>
                <Button Style="{StaticResource defaultStyle}"/>
                <Button Style="{StaticResource defaultStyle}"/>
                <Button Style="{StaticResource SecondStyle}"/>
            </StackPanel>
        </Grid>