テキスト コンテンツを白から黒に変更するマウスオーバー スタイルを指定する標準をButton
Style
アプリケーション全体に適用しています。これを実現するために、ボタン テンプレートを変更し、 を削除してContentPresenter
に置き換えてみましたTextBlock
。ただし、これは、次のような混合コンテンツを使用できないことを意味します。
<Button
<Button.Content>
<StackPanel Orientation="Horizontal">
<Path Margin="3" Width="12.375" Height="9.70833" Canvas.Left="0" Canvas.Top="0"
Stretch="Fill" Fill="#FF115485"
Data="F1 M 18.8333,7.08333L 16.7083,4.91667L 10.5,10.5417L 8.52083,8.6875L 6.45833,10.4792L 10.4792,14.625L 18.8333,7.08333 Z "/>
<TextBlock Margin="3">Hello</TextBlock>
</StackPanel>
</Button.Content>
</Button>
状況を改善するために、次にContentPresenter
戻るを入れ、(テキストのみの)ボタンに次のContentTemplate
ように指定しました:
<Button IsDefault="True" Content="Text only Button"
ContentTemplate="{StaticResource TextButtonTemplate}"
Command="{Binding ...}"
CommandParameter="{...}" />
そして、以下のようにTemplate
定義されています。このテンプレートはButton
テキスト コンテンツの でのみ機能し、他のテンプレートは混合コンテンツの必要に応じて定義されています。
<DataTemplate x:Key="TextButtonTemplate">
<TextBlock Text="{TemplateBinding Content}"
Foreground="{Binding Path=Foreground,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Button}}" />
</DataTemplate>
カスタム テンプレートを定義しなくても、目的のマウスオーバー スタイルを維持することで、これをさらに改善できる方法があるかどうかは誰にもわかりませんか?