- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 WPF 系统托盘栏应用程序。右键单击托盘栏图标时,会出现 ContextMenu
使用 HierarchicalDataTemplate
获得 2 级动态填充菜单。它可以工作,但是第二级项目的“可点击”部分没有正确拉伸(stretch)到父控件的可用宽度。而是参见图片:
现在用户必须单击 MenuItem
的较暗部分(文本所在的位置)执行Command
这个项目的。我希望整个菜单行能够触发 Command
.
这是我的 XAML:
<CollectionViewSource x:Key="Items" Source="{Binding Path=Items}" />
<ContextMenu x:Shared="false" x:Key="Menu" HorizontalContentAlignment="Stretch">
<ContextMenu.ItemTemplate>
<HierarchicalDataTemplate DataType="SystemTrayItemsViewModel" ItemsSource="{Binding Items}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Converter={StaticResource TabIconConverter}}" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<MenuItem Header="{Binding Text}" ToolTip="{Binding ToolTip}" Command="{Binding ToClipBoardCommand}" HorizontalContentAlignment="Stretch" />
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</ContextMenu.ItemTemplate>
<ContextMenu.ItemsSource>
<CompositeCollection>
<CollectionContainer Collection="{Binding Source={StaticResource Items}}">
</CollectionContainer>
<Separator />
<MenuItem Header="Exit" cal:Message.Attach="ExitApplication" />
</CompositeCollection>
</ContextMenu.ItemsSource>
</ContextMenu>
最佳答案
我刚刚在 another SO question 中找到了答案.
似乎问题在于指定 MenuItem
在 ItemTemplate
内. ContextMenu
显然是在包装另一个 MenuItem
围绕ItemTemplate
,导致这种嵌套效应。相反,您必须通过 MenuItem
执行此操作的Style
:
<ContextMenu>
<ContextMenu.Resources>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Header" Value="{Binding Text}"/>
<Setter Property="ToolTip" Value="{Binding ToolTip}"/>
<Setter Property="Command" Value="{Binding ToClipBoardCommand}"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ContextMenu.Resources>
</ContextMenu>
关于wpf - HierarchicalDataTemplate.ItemTemplate 中的水平拉伸(stretch) WPF ContextMenu MenuItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48597371/
这个问题在这里已经有了答案: How to configure ContextMenu buttons for delete and disabled in SwiftUI? (4 个回答) 4 个月
我在弄清楚如何设置正确的 DataContext 时遇到了一些麻烦。在 ContextMenu . 我有一组 View 模型,它们是 ItemsControl 的来源.每个 View 模型都有一个项目
我正在寻找一个关于在 WPF 中设置 ContextMenu 和 ContextMenu Items 样式的好例子。我想要的是 ContextMenu、Menu 和 MenuItems 如何一起玩的分
我的 WPF XAML 中定义了一个上下文菜单,如下所示: 我使用 System.Windows.Forms.NotifyIcon“myIcon”作为我的托盘
我在基于 Canvas 的 WPF 中制作了一个非常漂亮的 NodeGraph,现在我正在通过右键单击菜单添加漂亮的功能。 这些菜单是上下文相关的。这意味着右键单击图表的背景将显示图表上下文菜单,而右
如何复制我在一个 ContextMenu 中创建的 MenuItem 并将其复制以便我可以在第二个 ContextMenu 中使用它? 我试图直接复制它并删除它,但我得到元素已经有一个逻辑父元素。它必
registerForContextMenu(validate_button); @Override public void onCreateContextMenu(ContextMenu m
我正在使用 jquery contextmenu plugin这是我的 DEMO 下面是我的代码: $(function () { $.contextMenu({ sele
我正在使用 MVVM 将 View 绑定(bind)到树中的对象。我有一个实现树中项目的基类,该基类有一个 ContextMenu 属性: public IEnumerable Context
在旧 View 模型中有一个 ContextMenu 属性 ` public static ContextMenu DropDownMenu { get { return _Dr
Chrome 会触发 contextmenu 事件,但不会触发右键单击的 click 事件。 Firefox 会触发两者。 我正试图找到一些官方引用或解释,我很惊讶我从来没有遇到过这个。 http:/
默认情况下 JavaFX TextField有一个内置 ContextMenu带有“撤消”、“复制”、“剪切”等选项。 ComboBox也有同样的ContextMenu当它被设置为可编辑时( Comb
右键单击后,我一直坚持管理上下文菜单。实际上,我需要为文件夹显示一些上下文菜单项,为文件夹显示一些上下文菜单项。 单击文件夹上下文菜单将如下所示: create remove rename new 单
我正在尝试为 ScrollBars 替换 ContextMenu,我已经编写了这段代码:
我有一些 ContextMenu 和一些 menuItems。 menuItems 之一是“添加项目...”。当用户选择这个项目时,他应该看到带有可用项目列表的子菜单; 这是我的上下文菜单的描述: A
我想使用 jQuery.contextMenu: http://abeautifulsite.net/blog/2008/09/jquery-context-menu-plugin 在 jQuery.
我有包含多个项目的 ListBox(SelectionMode=Extended),我想添加上下文菜单功能。问题是如何根据某些条件动态创建上下文菜单。例如。如果只选择了一个项目,我想显示常规上下文菜单
我有一个通过数据绑定(bind)获取菜单项的上下文菜单(我使用的是 MVVM 模式): 这工作正常。但是,在没有要显示的菜单项的情况下,我根本不希望显示上下文菜单。有没有办法做到这一点?某种 XAM
我正在学习javafx.scene.control.ContextMenu,现在我面临一个问题: 如何从EventHandler获取被点击的对象? event.source() 和 event.tar
所以我有一个复杂的上下文菜单。它不只是菜单项。它也有单选按钮,底部有一个堆栈面板,上面有一个整数上下框。
我是一名优秀的程序员,十分优秀!