标签:
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:UC="clr-namespace:WpfApplication1" xmlns:UC1="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1" xmlns:sys="clr-namespace:System;assembly=mscorlib" Title="Window1" Height="300" Width="300"> <Window.Resources> <!-- Button控件样式 --> <Style TargetType="Button"> <Setter Property="Background" Value="Pink"/> <Setter Property="FontSize" Value="22"/> </Style> <!-- XAML的Class --> <Style x:Key="mystyle" TargetType="ContentControl"> <Setter Property="Background" Value="Peru"/> <Setter Property="FontSize" Value="30"/> </Style> <!-- 继承mystyle --> <Style x:Key="mystyle2" TargetType="ContentControl" BasedOn="{StaticResource ResourceKey=mystyle}"> <!--覆盖基类样式--> <Setter Property="Background" Value="Red" /> </Style> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="*"/> <RowDefinition Height="*"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Button Content="Button" Grid.Row="0"/> <Button Style="{StaticResource ResourceKey=mystyle}" Content="XAML的Class" Grid.Row="1"/> <Button Style="{StaticResource ResourceKey=mystyle2}" Content="样式的继承mystyle" Grid.Row="2"/> <Button Content="Button嵌入样式" Grid.Row="3"> <Button.Resources> <Style TargetType="Button" > <Setter Property="Background" Value="Coral"></Setter> </Style> </Button.Resources> </Button> </Grid> </Window>
<Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:UC="clr-namespace:WpfApplication1" xmlns:UC1="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1" xmlns:sys="clr-namespace:System;assembly=mscorlib" Title="Window1" Height="300" Width="300"> <Window.Resources> <Style x:Key="TriggersStyle" TargetType="Label"> <Setter Property="Background" Value="BurlyWood"/> <Style.Triggers> <!--Triggers单一条件触发事件 当IsMouseOver的时候,Button颜色变成粉色 --> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Pink"/> </Trigger> </Style.Triggers> </Style> <Style x:Key="MultiTriggerStyle" TargetType="Button"> <Setter Property="Background" Value="BurlyWood"/> <Style.Triggers> <!--MultiTrigger多条件触发事件 当IsMouseOver后IsPressed时候,字体30号 --> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True"></Condition> <Condition Property="IsPressed" Value="True"></Condition> </MultiTrigger.Conditions> <Setter Property="FontSize" Value="30"/> </MultiTrigger> </Style.Triggers> </Style> <Style x:Key="DataTriggerStyle" TargetType="Control"> <Setter Property="Background" Value="Brown"/> <Style.Triggers> <!-- 绑定当前的radio单选框,如果按钮选中,触发字体设置 --> <DataTrigger Binding="{Binding ElementName=radio, Path=IsChecked}" Value="True"> <Setter Property="FontSize" Value="30"/> </DataTrigger> </Style.Triggers> </Style> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"></ColumnDefinition> </Grid.ColumnDefinitions> <Label Style="{StaticResource ResourceKey=TriggersStyle}" Content="Triggers"></Label> <Button Style="{StaticResource ResourceKey=MultiTriggerStyle}" Content="MultiTrigger" Grid.Row="1"></Button> <RadioButton Style="{StaticResource ResourceKey=DataTriggerStyle}" Name="radio" Content="我要变成20号字" Grid.Row="2"></RadioButton> </Grid> </Window>
标签:
原文地址:http://www.cnblogs.com/lgxlsm/p/5122962.html