c# - C# WPF 中的上下文菜单绑定(bind)

标签 c# wpf binding contextmenu

当您将可观察集合设置为上下文菜单的项目源时,它会列出每个项目的类型...我想将集合中这些项目的名称字段绑定(bind)到标题...我不能似乎想出办法

最佳答案

使用DisplayMemberPath并将属性(property)的名称放在您的元素上。或者你可以使用 ItemTemplate属性(property)。

例子:

<ContextMenu ItemsSource="{Binding YourCollection}"
             DisplayMemberPath="Name" />

关于c# - C# WPF 中的上下文菜单绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8188257/

相关文章:

c# - 构建复杂的条件绑定(bind)的最佳方式

c# 并非所有代码路径都返回值错误

WPF DataGrid ComboBox 导致 InvalidOperationException

wpf - 如何使 WPF DrawingImage 元素的颜色动态化?

c# - 为什么用户控件不从 View 模型绑定(bind)?

.net - 将 FontStyles 和 FontWeights 绑定(bind)到 WPF ComboBox

Android Kotlin Kotlinx 模块级别 View 绑定(bind)

c# - 使用 iTextSharp 为文本部分加下划线

C# 位置问题

c# - Winforms 中的自定义 ListView?