2011-11-01 2 views
1

그럼 내가 트리거가 예상대로 작동하지 않습니까?

어떤 방법 메신저

은 메트로 스타일 WPF 테마를 만들려고 .. 여기에 뭔가가 메신저를 추측, 그래서이 시작 :

<Color x:Key="PrimaryColor">#8CBF26</Color> 
<Color x:Key="TextColor">White</Color> 
<Color x:Key="BackgroundColor">Black</Color> 

<SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource ResourceKey=PrimaryColor}" /> 
<SolidColorBrush x:Key="ForgroundBrush" Color="{StaticResource ResourceKey=TextColor}" /> 
<SolidColorBrush x:Key="BackgroundBrush" Color="{StaticResource ResourceKey=BackgroundColor}" /> 

<FontFamily x:Key="FontFamily">Segoe WP, Segoe UI, Lucida Sans Unicode, Verdana</FontFamily> 

<Style TargetType="{x:Type Window}"> 
    <Setter Property="Background" Value="{StaticResource BackgroundBrush}" /> 
</Style> 
<Style TargetType="{x:Type Run}"> 
    <Setter Property="FontWeight" Value="Bold" /> 
    <Setter Property="FontFamily" Value="{StaticResource FontFamily}" /> 
    <Setter Property="Foreground" Value="{StaticResource ForgroundBrush}" /> 
</Style> 
<Style TargetType="{x:Type TextBlock}"> 
    <Setter Property="FontWeight" Value="Bold" /> 
    <Setter Property="FontFamily" Value="{StaticResource FontFamily}" /> 
    <Setter Property="Foreground" Value="{StaticResource ForgroundBrush}" /> 
</Style> 

<Style TargetType="{x:Type Button}"> 
    <Setter Property="Background" Value="{StaticResource BackgroundBrush}"/> 
    <Setter Property="BorderBrush" Value="{StaticResource ForgroundBrush}"/> 
    <Setter Property="BorderThickness" Value="2"/> 
    <Setter Property="Foreground" Value="{StaticResource ForgroundBrush}"/> 
    <Setter Property="HorizontalContentAlignment" Value="Center"/> 
    <Setter Property="VerticalContentAlignment" Value="Center"/> 
    <Setter Property="Padding" Value="1"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Button}"> 
       <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" > 
        <ContentPresenter Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" 
             SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
             VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
             HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" /> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsPressed" Value="true"> 
         <Setter Property="Background" Value="{StaticResource ForgroundBrush}" /> 
         <Setter Property="Foreground" Value="{StaticResource BackgroundBrush}" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

그럼이 모든 위대한 작품하지만 트리거 Foreground 속성은 수정되지 않습니다. 내 생각에 TextBlock 스타일이 이미 있으므로이 문제에 대한 해결 방법이 있습니까?

감사

답변

2

편집 :TextBlock 스타일은 어떻게 든 자신 만의 스타일을 무시 ButtonControlTemplate 내부에 적용됩니다. 그것에 대해 무엇을해야할지 모르겠습니다. 나를 위해


작품, 당신은 Button 인스턴스에서 Foreground을 설정 했습니까? 그렇다면 precedence으로 인해 트리거를 무시합니다.

+0

버튼의 스타일은 전경색과 배경색을 모두 정의합니다 ... 스타일은 적용되지만 단추를 클릭하면 전경색이 변경되지 않습니다 ... – Peter

+0

@Petoj : 글쎄, 내가 말했듯이 나를 위해. 방금 모든 것을 일부 리소스에 복사하고 단추를 만들었고 누를 때 배경이 흰색으로 바뀌고 전경이 검은 색으로 변합니다. –

+0

Im 완전히 혼란스러워서 아픈 프로젝트를 만들고 거기서 시도해보십시오! – Peter

관련 문제