2016-07-06 13 views
1

スタイルテンプレートを使用してツールチップのテキストの色を変更しようとしています。しかし、ツールヒントのForegroundプロパティを変更しても、私が何をしても色は変わりません。私はこれをオーバーライドしているTextBlockスタイルも持っているので、これがほぼ確実です。ツールヒントスタイルテンプレートのテキストが機能しない

新しいテキストブロックでテンプレートを再作成しようとすると、全く効果がありません。私は昨日、この問題を手引きし、スレッドを検索して何も見つけていませんでした。一切の貢献は感謝します。

これは私のリソースディクショナリでスタイルです:

<!-- TextBlock --> 
<Style TargetType="{x:Type TextBlock}"> 
    <Setter Property="OverridesDefaultStyle" Value="True" /> 
    <Setter Property="SnapsToDevicePixels" Value="True" /> 
    <Setter Property="Foreground" Value="#B2FFFFFF"/>  <!-- ToolTip text color overridden by this --> 
</Style> 

<!-- ToolTip --> 
<Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource {x:Type ToolTip}}"> 
    <Setter Property="OverridesDefaultStyle" Value="true"/> 
    <Setter Property="HasDropShadow" Value="True" /> 
    <Setter Property="Foreground" Value="DarkBlue"/> <!-- has no effect --> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ToolTip"> 
       <Grid> 
        <Border Name="Border" 
          Width="{TemplateBinding Width}" 
          Height="{TemplateBinding Height}" 
          MinWidth="100" 
          MinHeight="30" 
          Margin="0,0,0,50" 
          Background="Beige" 
          BorderBrush="Black" 
          BorderThickness="1" 
          CornerRadius="10"/> 
        <TextBlock Foreground="DarkBlue"/> <!-- has not effect --> 
        <ContentPresenter Margin="4" 
             HorizontalAlignment="Center" 
             VerticalAlignment="Top" 
             Content="{TemplateBinding Content}" 
             ContentTemplate="{TemplateBinding ContentTemplate}"/> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+1

詳細をご覧ください。 XAMLは問題ありません。 – cdmnk

+0

'ContentPresenter'の前に' TextBlock'をどうするべきですか? – lokusking

+0

ところで、あなたのスタイルは私のマシンでうまくいきます。 – lokusking

答えて

1

私はこの問題の一つの解決策を考え出しました。

<ControlTemplate TargetType="ToolTip"> 

のように読み取ること:この行からTargetTypeに取り外し

<ControlTemplate > 

をさらにダウンのControlTemplateには、テキストブロックは次のように設定されるべきである:

<TextBlock 
    Text="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" 
    Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}}"> 
</TextBlock> 

これにより、ツールヒントのテキスト色をToolTipの「Foreground」プロパティで設定でき、他のTextBlockスタイルでは使用できません。

関連する問題