<Style x:Key="MyStyle">
<Setter Property="Window.Background" Value="Orange"/>
</Style>
<Button Content="Ok" Style="{StaticResource MyStyle}"/>
Run Code Online (Sandbox Code Playgroud)
如果将setter指定为Window.Background,为什么按钮实际上是橙色背景?
这并没有给TextBlock的橙色背景:
<TextBlock Style="{StaticResource MyStyle}"/>
Run Code Online (Sandbox Code Playgroud)
谢谢
既没有Button也没有Window实际定义Background属性,它们都继承了它Control.
所以即使你写了Window.Background,setter实际上也是通过使用Control.BackgroundProperty也应用于的字段绑定到属性Button.
| 归档时间: |
|
| 查看次数: |
67 次 |
| 最近记录: |