WPF学习系列021: 3.2.3 属性值继承

 

  •  
    1. 属性值继承与传统的类的继承不同,它指的是属性值自顶向下沿着元素树传递。
    1. 并不是每个依赖属性都参与属性值的继承
    2. 属性的值可能由一些优先级更高的源设置
    1. 属性值可以被传递给一些并非逻辑树或可视树中的子元素。例如:元素的触发器等。
  • 3.2.3 属性值继承

    例如:

    <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="About WPF Unleashed"

    SizeToContent="WidthAndHeight"

    FontSize="30"

    FontStyle="Italic"

    Background="OrangeRed">

    <StackPanel>

    <Label FontWeight="Bold"

    FontSize="20"

    Foreground="White">

    WPF Unleashed (Version 3.0)

    </Label>

    <Label>

    © 2006 SAMS Publishing

    </Label>

    <Label>

    Installed Chapters:

    </Label>

    <ListBox>

    <ListBoxItem>

    Chapter 1

    </ListBoxItem>

    <ListBoxItem>

    Chapter 2

    </ListBoxItem>

    </ListBox>

    <StackPanel Orientation="Horizontal"

    HorizontalAlignment="Center">

    <Button MinWidth="75"

    Margin="10">

    Help

    </Button>

    <Button MinWidth="75"

    Margin="10">

    OK

    </Button>

    </StackPanel>

    <StatusBar>

    You have successfully registered this product.

    </StatusBar>

    </StackPanel>

    </Window>

    这里对 Window 设置的 FontSize FontStyle 属性将传递到其下元素树的每个元素。由于Label 已经显式设置了 FontSize 的值,这将重载从 Window 继承的 FontSize 的值,因此字体大小与设置的值相同。StatusBar的文本不受任何值的影响,因此其字体大小和类型都不会发生变化。

    例如:StatusBarMenuToolTrip控件,其内部会把字体属性设置为当前的系统设置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值