wpf的style和web端的差不多。都是上面定义,下面使用。等级越低,优先级越高
我是在这学的:
https://www.bilibili.com/video/BV1nY411a7T8/?p=2&vd_source=b6991929b1d37895e965acaa56537632
<Window.Resources>
<Style x:Key="baseBtn" TargetType="Button">
<!-- TargetType:这个style是给哪个控件的,button还是checkbox -->
<Setter Property="FontSize" Value="30"/>
<Setter Property="Background" Value="Red"/>
<Setter Property="FontFamily" Value="正楷"/>
</Style>
<Style x:Key="btnStyle1" TargetType="Button" BasedOn="{StaticResource baseBtn}" >
<!--BasedOn:继承同类型的style 如果有重复的元素,本级设置的元素值 优先级最高-->
<Setter Property="FontSize" Value="14"/>
</Style>
</Window.Resources>
<Grid>
<StackPanel Orientation="Horizontal">
<Button Height="120" Width="120" Style="{StaticResource btnStyle1}" Content="我是btn1" />
<!--Style:继承-Window.Resources的 Style>-->
<Button Height="120" Width="120" Content="我是btn2" Style="{StaticResource baseBtn}" />
<Button Height="120" Width="120" FontSize="20" Background="Aquamarine" Content="我是btn2" Style="{StaticResource btnStyle1}" />
<!--直接在控件里定义Background的值,优先使用控件的值。等级余额低,优先级越高-->
<CheckBox Height="120" Width="156" FontSize="21" Background="Red" Content="CheckBox" Margin="0,150,0,149"/>
</StackPanel>
</Grid>
------------------------------------↓↓↓↓效果图↓↓↓↓----------------------------------------------