ボタンが通常 1 本の水平線のように見える単純なボタン テンプレートを作成しようとしていますが、マウスを重ねるとボタンの後ろに「四角形」の塗りつぶしが表示されます。これは私が持っているコードですが、トリガーを起動できないようです。
<Window x:Class="TestStylingWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="36" GlassFrameThickness="0 0 0 1" ResizeBorderThickness="5" />
</WindowChrome.WindowChrome>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="36" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Height="36" Width="36"
HorizontalAlignment="Center" VerticalAlignment="Center"
Grid.Row="0">
<Button.Template>
<ControlTemplate>
<Grid>
<Rectangle x:Name="PART_ButtonBackgroundRectangle" Fill="LightGray" Width="36" Height="36" Opacity="0" />
<Path x:Name="PART_ButtonPath" Data="M10,26 L26,26" Stroke="DarkGray" StrokeThickness="1.5" />
</Grid>
<ControlTemplate.Triggers>
<Trigger SourceName="PART_ButtonBackgroundRectangle" Property="IsMouseOver" Value="True">
<Setter TargetName="PART_ButtonBackgroundRectangle" Property="Opacity" Value="1" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</Window>
私のトリガーが機能しない理由、またはこれを行うためのより良い方法を誰かが知っていますか? 私はWPFが初めてで、これをリファクタリングしたいと思っています(多くのボタンで使用するために)が、方法がわかりません。
更新:わかりました。ボタンがウィンドウのキャプション バー内にあるためだと思います。これを回避する良い方法はありますか?ボタンにクリック/ホバーの優先度を設定する方法はありますか?