key值调用

key值调用
作者:邱名涛
撰写时间:2019年5月14日

<Window x:Class="WpfApplication1.Demo2"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="Demo2" Height="300" Width="300">

    <Window.Resources>
        <!--样式资源-->
        <Style x:Key="ButtonStyle" TargetType="Button"> <!--定义的key值可以多处调用-->
            <!--背景色-->
            <Setter Property="FontSize" Value="24"/>
            <Setter Property="Background">
                <Setter.Value>
                    <LinearGradientBrush 
StartPoint="0,0" 
EndPoint="1,1" 
MappingMode="RelativeToBoundingBox"><!--MappingMode绘图模型-->
                       <GradientStop Color="Black" Offset="0"></GradientStop>
                       <GradientStop Color="White" Offset="1"></GradientStop>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
   
    <!--页面布局-->
    <Grid>
        <!--依赖属性:绑定Style="{StaticResource ButtonStyle}-->
        <Button Content="依赖属性测试" 
Style="{StaticResource ButtonStyle}" 
Height="80" 
Margin="0,110,-0.4,80.4">
</Button><!--没有设定颜色调用了key值即可获取key值的元素-->
        <!--依赖属性:优先级(属性默认复制优先Background="Yellow"  FontSize="39")-->
        <Button  Content="依赖属性优先级"
Background="Yellow" 
FontSize="39" 
Style="{StaticResource ButtonStyle}"
Height="80" 
Margin="0,190,-0.4,0.4">
</Button><!--设定颜色调用了key值即无效-->
    </Grid>
</Window>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值