2010-08-12 103 views
0

我想问一个关于该代码的问题,它的简单XAML代码如下所示。wpf财产继承

<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将是斜体,这样的问题是!为什么在根目录下的所有控件的fontstyle都会受到影响,但按钮的背景却不是?

回答

0

我想按钮的ControlTemplate会根据windows ui-guidelines明确设置Background-brush。因此,对于Control.BackgroundProperty,属性继承被破坏。

为了证明它,也许this工具将有所帮助。

+0

所以我一定要记住哪些属性可以被打破或不!我需要坚实的回答逻辑 – user418308 2010-08-12 11:48:49

0

这是默认的按钮模板,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> 
+0

抱歉,但我没有得到它!我仍然没有得到我的答案。 – user418308 2010-08-12 11:47:45

+0

默认按钮由Microsoft_Windows_Themes组成:ButtonChrome,在那里他们为背景提供了一个静态资源,这就是为什么按钮不显示背景。 – 2010-08-12 13:01:38