繁体   English   中英

wpf属性继承

[英]wpf property inheritance

我想问一个关于该代码的简单XAML代码的问题,如下所示。

<Window x:Class="WpfApplication15.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" Background="Orange" FontStyle="Italic">
<StackPanel>
    <Label>blo</Label>
    <Button>hi</Button>
    <Button>hi2</Button>
</StackPanel>
</Window>

因此,我们可以简单地想象一下,将背景标记为橙色,但是将按钮的背景色设为橙色将作为默认值,但是所有控件FontStyle将变为斜体,所以问题就在于此! 为什么在根目录下所有控件的字体样式都会影响到按钮的背景却没有?

我想按钮的ControlTemplate相对于Windows ui指南明确地设置了背景画笔。 因此, Control.BackgroundProperty属性继承被破坏了。

为了证明这一点,也许这个工具会有所帮助。

这是默认按钮模板的定义,Microsoft_Windows_Themes:ButtonChrome可以解决问题

                    <ControlTemplate TargetType="{x:Type Button}">
                    <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" RenderDefaulted="{TemplateBinding IsDefaulted}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
                    </Microsoft_Windows_Themes:ButtonChrome>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM