c# - 在 WPF 中使用 ToolBarTray 控件进行数据绑定(bind)

标签 c# wpf data-binding

我正在开发 WPF/PRISM 应用程序。我首先按照以下示例使用数据绑定(bind)创建动态菜单:http://www.koaxkoaxkoax.com/ribbit/2010/09/creating-dynamic-menus-in-wpf.html 它使用 HierarchicalDataTemplate,这似乎是一个不错的解决方案。

我的目标是对工具栏使用相同的概念,但遗憾的是 ToolBarTray 控件没有 ItemsSource 来动态生成工具栏控件。

我是 WPF 的新手,我似乎找不到使用数据绑定(bind) 在 ToolBarTray 中创建工具栏的好的解决方案。有人有解决方案吗?

HierarchicalDataTemplate 是否可行?

谢谢

最佳答案

虽然 ToolBarTray 不包含 ItemsSource 属性,但它确实包含您可以绑定(bind)到的 ToolBars 属性。然后,每个 ToolBar 都有一个您也可以绑定(bind)到的 ItemsSource 属性。

所以你的绑定(bind)看起来像这样:

<ToolBarTray ToolBars="{Binding MyToolBarsProperty}" />

然后您可以开始在工具栏上使用 HierarchicalDataTemplates:

<HierarchicalDataTemplate.ItemContainerStyle>
    <Style TargetType="Button">
        <Setter Property="Command" Value="{Binding Command}"/>
    </Style>
</HierarchicalDataTemplate.ItemContainerStyle>

关于c# - 在 WPF 中使用 ToolBarTray 控件进行数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21556134/

相关文章:

C# WPF 应用程序 : What is "this"?

html - knockout : nest input element in label tag with data-bind properties

C# - 检查列表是否包含属性等于值的对象?

c# - ASP.Net MVC4 自定义路由

c# - 如何为颜色选择器 (wpf) 创建颜色 Canvas

wpf - 自定义控件依赖属性集合,计算嵌套控件项

c# - WPF 中自动生成的代码显示错误。 (C#、WPF、Visual Studio 社区 2013)

c# - 我得到数据绑定(bind) : 'System.Data.DataRowView' does not contain a property with the name 'productID'

c# - 在非开发机器上使用逐步调试所需的最低要求

c# - 应用程序在处理所有事件之前退出 - 基于事件的异步模式