Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 删除右键单击事件的ListBoxItem背景_C#_Wpf_Xaml_Listbox_Listboxitem - Fatal编程技术网

C# 删除右键单击事件的ListBoxItem背景

C# 删除右键单击事件的ListBoxItem背景,c#,wpf,xaml,listbox,listboxitem,C#,Wpf,Xaml,Listbox,Listboxitem,我已设法阻止列表框项目背景在悬停和选择时显示,但是,当我右键单击某个项目时,它会出现,甚至当列表框再次具有焦点时,它会在悬停时显示背景(对于以前右键单击的元素) 我不能在ListBoxPreviewMouseDown中使用e.Handled=true,因为这会破坏我的右键单击上下文菜单。我所说的中断是指它阻止菜单项对点击做出反应。关联菜单显示良好,但无法调用项目单击 右键单击时未显示的ListBoxItem背景,我还缺少什么 多谢各位 只需始终将列表框的ItemContainerStyle属性设

我已设法阻止
列表框
项目背景在悬停和选择时显示,但是,当我右键单击某个项目时,它会出现,甚至当
列表框
再次具有焦点时,它会在悬停时显示背景(对于以前右键单击的元素)

我不能在
ListBoxPreviewMouseDown
中使用
e.Handled=true
,因为这会破坏我的右键单击上下文菜单。我所说的中断是指它阻止菜单项对点击做出反应。关联菜单显示良好,但无法调用项目单击

右键单击时未显示的
ListBoxItem
背景,我还缺少什么

多谢各位


只需始终将
列表框的
ItemContainerStyle
属性设置为自定义样式,即不要在
样式内的触发器中设置它:

<ListBox Name="ListBoxOne">
    <ListBox.Style>
        <Style TargetType="ListBox">
            <Setter Property="ItemContainerStyle" Value="{StaticResource MyListBoxItemStyle}"/>
        </Style>
    </ListBox.Style>
</ListBox>


为什么不使用彻底解决问题的
ItemsControl
。这当然是一个以假乱真的例子。谢谢你的帮助!