ボタンなどを含む WPF グリッドがあります。
ボタンはデフォルトで非表示になっており、マウスがグリッド上にある場合にのみ表示されます。(機能的には、グリッドはタブ ヘッダーであり、「消える」ボタンは閉じるボタンです)。また、カスタム感を出すためにボタン テンプレートを書き直しました。
これで、マウスがグリッドに入るとボタンが表示されますが、マウスがボタンに入るとすぐに消えます。私の直感では、マウスがボタンに移動すると、グリッドの IsMouseOver が False になります。これを回避する方法はありますか?
<ControlTemplate x:Key="CloseTabButtonTemplate">
<Border Width="14" Height="14" Margin="3"
HorizontalAlignment="Right"
VerticalAlignment="Center"
BorderThickness="1"
CornerRadius="2,2,2,2">
<TextBlock Text="x" VerticalAlignment="Center" HorizontalAlignment="Center"
FontSize="11" Padding="0" Margin="0,-2,0,0" Foreground="White"/>
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Background" Value="#33DA3030"/>
<Setter Property="BorderBrush" Value="White"/>
<Setter Property="Visibility" Value="Hidden"/>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Grid}},Path=IsMouseOver}" Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFDA3030"/>
<Setter Property="Visibility" Value="Visible" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
</ControlTemplate>
<Button Grid.Column="2" HorizontalAlignment="Right" Template="{StaticResource CloseTabButtonTemplate}">x</Button>
ありがとう!