我正在开发 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/