码迷,mamicode.com
首页 > Windows程序 > 详细

windo phone8.1 样式的基本使用(一)

时间:2015-02-03 00:31:17      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

                      样式的基本使用(一)

当一个项目中有多个控件出现相同的属性设置,那么可以使用以下解决办法

 

方法一:

<Page.Resources>

    <!--向资源字典中添加一个键为Buttonground,值为SolidColorBrush对象-->

    <SolidColorBrush 

            x:Key="ButtonBackground"

            Color="Aqua"/>

    <SolidColorBrush

            x:Key="ButtonForeground"

            Color="Red"/>

    <x:Double x:Key="ButtonFontSize">30</x:Double>

</Page.Resources>

<Grid>

    <Button

            Content="Button"

            Background="{StaticResource ButtonBackground}"

            Foreground="{StaticResource ButtonForeground}"

            FontSize="{StaticResource ButtonFontSize}"/>

</Grid>

 

方法二:

<Page.Resources>

    <Page.Resources>

        <!--类型选择器-->

        <!--键是唯一的,不能重复定义-->

        <!--style节点可以不用指定一个具体的键,有一个默认的键(typeof(Button))-->

        <Style TargetType="Button">

            <Setter Property="Width" Value="200"/>

        </Style>

        <!--解决类型选择器重名的问题-->

        <Style x:Key="ButtontowStyle" TargetType="Button">

            <Setter Property="Width" Value="300"/>

            <Setter Property="Background">

                <Setter.Value>

                    <SolidColorBrush Color="Aqua"/>

                </Setter.Value>

            </Setter>

        </Style>

    </Page.Resources>

    <StackPanel>

        <Button

            Content="Button1"/>

        <!--Button的Style默认指向的键为this.GetType()-->

        <Button

            Content="Button2"

            Style="{StaticResource ButtontowStyle}"/>

</StackPanel>

 

 

 

 

windo phone8.1 样式的基本使用(一)

标签:

原文地址:http://www.cnblogs.com/fenger-VIP/p/4268937.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!