2016-05-02 17 views
0

を含むのContentPresenterのフォアグラウンドカラーを変更するには、幾何学的アイコンでスタイル私は、次のコードを持っているContentTemplateとのTextBlock

<Button Style="{StaticResource Button}" IsEnabled="False"> 
    <DockPanel> 
     <ContentControl Template="{StaticResource geometryMenuContentTemplate}" 
         DataContext="{StaticResource keyboardButtonGeometry}" 
         Style="{StaticResource TopBarIcon}" /> 
     <TextBlock Style="{StaticResource TopBarHeaderText}" Text="KEYBOARD"/> 
    </DockPanel> 
</Button> 

<ControlTemplate x:Key="geometryMenuContentTemplate" TargetType="ContentControl"> 
    <Canvas> 
     <Path Width="25" Height="25" Stretch="Fill" Fill="{TemplateBinding Foreground}" Data="{Binding}"/> 
    </Canvas> 
</ControlTemplate> 

<StreamGeometry x:Key="keyboardButtonGeometry"> 
    F1 M 15.8333,2... 
</StreamGeometry> 

とボタンである:

<Style x:Key="Button" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> 
    <Setter Property="Foreground" Value="{StaticResource StandardForegroundColor}" /> 
    <Setter Property="Template" Value="{StaticResource ButtonTemplate}" /> 
</Style> 

<ControlTemplate x:Key="ButtonTemplate" TargetType="Button"> 
    <Border BorderThickness="{TemplateBinding BorderThickness}" 
      BorderBrush="{TemplateBinding BorderBrush}" 
      Padding="{TemplateBinding Padding}" 
      Background="{TemplateBinding Background}"> 
     <ContentPresenter Name="ButtonContentPresenter" Margin="{TemplateBinding Padding}" TextBlock.Foreground="Red"/> 
    </Border> 
</ControlTemplate> 


<Style x:Key="TopBarHeaderText" TargetType="TextBlock" BasedOn="{StaticResource StatsHeaderText}"> 
    <Setter Property="Foreground" Value="White" /> 
</Style> 

の視覚的出力

Button aspect

I:私のコードは次のようですContentPresenter内のTextblockの前景色をButtonContentPresenterと赤色に変更したい(ButtonTemplate)。 私のコードは、アイコンの色のみを変更し、TextBlockは変更しませんでした。どうして? 変更方法Textblockのみ?私はこのような何かを取得したいと思います

:あなたのコードを読む

Final image

+0

あなたのTextBlockはContentControlの内部にはなく、あなたのスタイルは、TextBlockコントロールではなく、 –

答えて

1

を、私はあなたのTextBlockがTopBarHeaderTextという名前のスタイルを持っていることに気づいた、しかし、私は、あなたの質問にそのスタイルが表示されません。画像の色が変わるのは、{TemplateBinding Foreground}として設定されているからです。その設定をTextBlockのスタイル(TopBarHeaderTextスタイル)に入れることができますか?

geometryMenuContentTemplateとTopBarHeaderTextで誤って色定義を反転したように見えます(私が見ているコードから)。

関連する問題