KimhillZhang  

 <Window.Resources>
        <Style x:Key="button">
            <Setter Property="Button.FontSize" Value="30"/>
        </Style>
    </Window.Resources>
    <StackPanel>
        <Button Style="{StaticResource ResourceKey=button}" Content="HELLO"></Button>
    </StackPanel>

=========================================

<Button Content="HELLO">
            <Button.Style>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="FontSize" Value="30"/>
                </Style>
            </Button.Style>
 </Button>

===============================================

 

<Button Content="HELLO">
            <Button.Style>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Height" Value="60"/>
                    <Setter Property="Background">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="1,0" EndPoint="1,1">
                                <GradientStop Offset="1" Color="Blue"/>
                                <GradientStop Offset="0" Color="Red"/>
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
        </Button>

 

===================================

<Window.Resources>
        <Style x:Key="baseButton">
            <Setter Property="Button.FontSize" Value="30"/>
        </Style>
        <Style x:Key="subButton" BasedOn="{StaticResource ResourceKey=baseButton}" TargetType="{x:Type Button}">
            <Setter Property="Background" Value="Red"/>
        </Style>
    </Window.Resources>
    <StackPanel>
        <Button Content="HELLO" Style="{StaticResource ResourceKey=subButton}"></Button>
    </StackPanel>

 

===========================

 <Window.Resources>
        <Style x:Key="baseButton">
            <EventSetter Event="Button.MouseEnter" Handler="ButtonMouseEnter"/>
        </Style>
    </Window.Resources>
    <StackPanel>
        <Button Content="HELLO" Style="{StaticResource ResourceKey=baseButton}"></Button>
    </StackPanel>

 

 void ButtonMouseEnter(object sender, MouseEventArgs e)
        {
            ((Button)sender).Foreground = new SolidColorBrush(Colors.Red);
        }

 

 

==============================属性触发器

<Window.Resources>
        <Style x:Key="baseButton">
            <Style.Triggers>
                <Trigger Property="Control.IsMouseOver" Value="true">
                    <Setter Property="Control.FontStyle" Value="Italic"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <StackPanel>
        <Button Content="HELLO" Style="{StaticResource ResourceKey=baseButton}"></Button>
    </StackPanel>

 

==============================事件触发器

<Window.Resources>
        <Style x:Key="baseButton">
            <Style.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                           
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <StackPanel>
        <Button Content="HELLO" Style="{StaticResource ResourceKey=baseButton}"></Button>
    </StackPanel>

 

============控件模板

 <Button FontSize="20">
            <Button.Template>
                <ControlTemplate>
                    <Rectangle Fill="Red" RadiusX="10" RadiusY="10" Width="30" Height="20"/>
                </ControlTemplate>
            </Button.Template>
        </Button>

 

 

 <Window.Resources>
        <ControlTemplate x:Key="button">
            <Border BorderBrush="Orange" BorderThickness="3" CornerRadius="3" Background="Red"
                     TextBlock.Foreground="White">
                <ContentPresenter RecognizesAccessKey="True" Content="HELLO"></ContentPresenter>
            </Border>
        </ControlTemplate>
    </Window.Resources>
    <StackPanel>
        <Button FontSize="20" Height="30" Template="{StaticResource ResourceKey=button}">
         
        </Button>
    </StackPanel>

posted on 2012-03-23 23:03  KimhillZhang  阅读(497)  评论(0编辑  收藏  举报