2010-11-28 8 views
0

나는 내 app.xaml이 넣어 여러 제어 파생 된 형식에 대한 전역 스타일을 설정하려고 :WPF- 왜 이러한 스타일이 작동하지 않습니까?

<Style TargetType="{x:Type Control}"> 
    <Setter Property="Background" Value="{Binding BackgroundBrush, Source={x:Static m:Settings.Instance}, UpdateSourceTrigger=PropertyChanged}" /> 
    <Setter Property="Foreground" Value="{Binding ForegroundBrush, Source={x:Static m:Settings.Instance}, UpdateSourceTrigger=PropertyChanged}" /> 
    <Setter Property="BorderBrush" Value="{Binding ForegroundBrush, Source={x:Static m:Settings.Instance}, UpdateSourceTrigger=PropertyChanged}" /> 
    <Setter Property="UseLayoutRounding" Value="True" /> 
</Style> 

<Style TargetType="{x:Type Window}" BasedOn="{StaticResource {x:Type Control}}" /> 

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Control}}" /> 

현재 창 스타일은 비주얼 스튜디오 디자인 창에서 작동하고 버튼 스타일 아무튼 ' 전혀 일하지 않는다. 나는 무엇을 잘못 했는가?

+0

어떤 버전의 Visual Studio 및 .NET Framework를 사용하고 있습니까? 나는 .NET 4.0 (WPF 4.0)에서 작동하는 스타일을 얻는 데 어려움을 겪고있다. http://stackoverflow.com/questions/4239714/why-cant-i-style-a-control-with-the-aero-theme-applied-in-wpf-4-0을 참조하십시오. – devuxer

답변

1

BasedOn이 다소 특별하다는 것을 발견했습니다. 키를 할당하면 더 자주 작동하는 경향이 있습니다. 값 바인딩을 사용하여 외부 정적 클래스를 만들지 않았기 때문에 문제가 발생하는지 잘 모르겠습니다.

<Grid.Resources> 
    <Style x:Key="simpleStyle" TargetType="{x:Type Control}"> 
     <Setter Property="Background" Value="Blue" /> 
     <Setter Property="Foreground" Value="Yellow" /> 
     <Setter Property="BorderBrush" Value="CornflowerBlue" /> 
    </Style> 

    <Style TargetType="{x:Type Control}" BasedOn="{StaticResource simpleStyle}" /> 

     <Style TargetType="{x:Type Window}" BasedOn="{StaticResource simpleStyle}" /> 

    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource simpleStyle}" /> 
</Grid.Resources> 
<Button Height="50" Width="100"> 
    Hello 
</Button> 
관련 문제