win8第六步样式

内部样式

<Page
    x:Class="App2.StylePage1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.Resources>
        <Style TargetType="Button"> 如果不是设置x:key则页面内所有button均使用这个样式
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush>
                        <GradientStop Color="Red" Offset="0"></GradientStop>
                        <GradientStop Color="Blue" Offset="1"></GradientStop>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderBrush" Value="Blue"></Setter>
        </Style>
        <Style TargetType="Button" x:Key="btnStyle1">  只有Stype="{StaticResource btnStyle1}"才使用
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush>
                        <GradientStop Color="Yellow" Offset="0"></GradientStop>
                        <GradientStop Color="Green" Offset="1"></GradientStop>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderBrush" Value="Blue"></Setter>
        </Style>
    </Page.Resources>
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Button Content="Button" HorizontalAlignment="Left" Margin="286,99,0,0" VerticalAlignment="Top"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="391,99,0,0" VerticalAlignment="Top"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="490,99,0,0" VerticalAlignment="Top"/>
        <Button Content="Button" Style="{StaticResource btnStyle1}" HorizontalAlignment="Left" Margin="286,224,0,0" VerticalAlignment="Top"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="391,224,0,0" VerticalAlignment="Top"/>

    </Grid>
</Page>

外部样式

<Page
    x:Class="App2.BlankPage1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Page.Resources>
        <ResourceDictionary Source="SkinHot.xaml"></ResourceDictionary>    引入外部样式文件
    </Page.Resources>
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">    normalBtn为外部样式key
        <Button Style="{StaticResource normalBtn}" Content="Button" HorizontalAlignment="Left" Margin="534,149,0,0" VerticalAlignment="Top"/>
    </Grid>
</Page>

外部样式文件

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App2">
    <Style TargetType="Button" x:Key="normalBtn">
        <Setter Property="Background">
            <Setter.Value>
                <SolidColorBrush Color="Pink"></SolidColorBrush>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

 

posted @ 2014-03-20 17:15  东方小花猪  阅读(138)  评论(0编辑  收藏  举报