2010-08-12 6 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와 관련하여 명시 적으로 배경 브러시를 설정한다고 가정합니다. 따라서 Control.BackgroundProperty에 대한 속성 상속이 끊어졌습니다.

증명하려면 아마도 this 도구가 도움이 될 것입니다.

+0

그래서 내가 속성이 파손 여부를 할 수있는 기억해야 할 트릭을하고있다! 논리적으로 솔리드 대답이 필요합니다. – user418308

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

+0

기본 버튼은 Microsoft_Windows_Themes : ButtonChrome으로 구성되어 있으며 버튼이 배경을 표시하지 않는 이유 인 배경에 대한 정적 리소스를 제공합니다. –