zoukankan      html  css  js  c++  java
  • windo phone8.1 样式的基本使用(一)

                          样式的基本使用(一)

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

     

    方法一:

    <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>

     

     

     

     

  • 相关阅读:
    复杂JSON字符串转换为Java嵌套对象的方法
    好代码是如何炼成的
    让数据流转换代码更加健壮流畅:List的Stream包装
    由一个重构示例引发的对可扩展性的思考
    如何高效搜索信息
    个人安全防护简明指南
    YAML配置解析
    事件处理业务的简易组件编排框架
    lambda表达式滥用之殇:解耦三层嵌套lambda表达式
    碎碎念四六
  • 原文地址:https://www.cnblogs.com/fenger-VIP/p/4268937.html
Copyright © 2011-2022 走看看