ListBox
アイテムの背景がホバーと選択に表示されないようにすることができましたが、アイテムを右クリックすると表示され、さらにListBox
にフォーカスがある(以前に右クリックされた要素用)。右クリックイベントのListBoxItemのバックグラウンドを削除する
e.Handled = true
をListBoxPreviewMouseDown
で使用すると、右クリックのコンテキストメニューが表示されなくなります。ブレークは、メニュー項目がクリックに反応しないようにすることを意味します。コンテキストメニューは正常に表示されますが、アイテムのクリックを呼び出すことはできません。
右クリックしても表示されない背景は、ListBoxItem
にも表示されません。
ありがとうございます。
<!-- Style -->
<Style TargetType="ListBoxItem" x:Key="MyListBoxItemStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Bd"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="True">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
ContentTemplate="{TemplateBinding ContentTemplate}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="Transparent" />
<Setter TargetName="Bd" Property="BorderBrush" Value="Transparent" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="Transparent" />
<Setter TargetName="Bd" Property="BorderBrush" Value="Transparent" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="True" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="Bd" Property="Background" Value="Transparent" />
<Setter TargetName="Bd" Property="BorderBrush" Value="Transparent" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Bd" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- Listbox -->
<ListBox Name="ListBoxOne">
<ListBox.Style>
<Style>
<Style.Triggers>
<Trigger Property="ListBox.IsMouseOver" Value="True">
<Setter
Property="ListBox.ItemContainerStyle"
Value="{StaticResource MyListBoxItemStyle}"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.Style>
</userControls:ListBox>
はなぜ使用しないで '固定 –