<Window.Resources> <!--只对Control类及其派生类有效,若改成Button则只对Button有效--> <Style x:Key="Style1"> <Setter Property="Control.FontFamily" Value="Times New Roman" /> <Setter Property="Control.FontSize" Value="18" /> <Setter Property="Control.FontWeight" Value="Bold" /> </Style> <!--样式继承--> <Style x:Key="Style2" BasedOn="{StaticResource Style1}" > <Setter Property="Control.Foreground" Value="White"/> <Setter Property="Control.Background" Value="DarkBlue"/> </Style> <!--自动应用--> <Style TargetType="TextBlock"> <Setter Property="Foreground" Value="Red"/> <Setter Property="Background" Value="Orange"/> <!--关联事件处理函数--> <EventSetter Event="TextBlock.MouseEnter" Handler="element_MouseEnter"/> </Style> <!--触发器--> <Style x:Key="TriggerStyle"> <Style.Setters> </Style.Setters> <Style.Triggers> <!--简单触发器--> <Trigger Property="Control.IsFocused" Value="True"> <Setter Property="Control.Foreground" Value="DarkRed"/> </Trigger> <!--多条件触发器--> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="Control.IsFocused" Value="True"/> <Condition Property="Control.IsMouseOver" Value="True"/> </MultiTrigger.Conditions> <MultiTrigger.Setters> <Setter Property="Control.Foreground" Value="DarkRed"/> </MultiTrigger.Setters> </MultiTrigger> <!--事件触发器--> <EventTrigger RoutedEvent="Mouse.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard></BeginStoryboard> </EventTrigger.Actions> </EventTrigger> <!--数据绑定触发器--> <DataTrigger></DataTrigger> <MultiDataTrigger></MultiDataTrigger> </Style.Triggers> </Style> </Window.Resources> <StackPanel Width="200"> <Button Margin="5" Padding="5" Name="cmd1" Style="{StaticResource Style1}">基本样式</Button> <Button Margin="5" Padding="5" Name="cmd2" Style="{StaticResource Style2}">样式继承</Button> <TextBlock Text="自动应用"/> </StackPanel>
标签:基本,知识点,备忘录,样式,继承,WPF From: https://www.cnblogs.com/chixiner/p/17154821.html