Use data binding with ToolBarTray in WPF

Im working on a WPF / PRISM application. I started by creating a dynamic menu using data binding after this example: http://www.koaxkoaxkoax.com/ribbit/2010/09/creating-dynamic-menus-in-wpf.html It uses a HierarchicalDataTemplate , which seems like a good solution.

My goal was to use the same concept for toolbars, but unfortunately the ToolBarTray control does not have an ItemsSource to dynamically create toolbar elements in it.

Im pretty new to WPF, and I can't find a suitable solution for creating toolbars inside ToolBarTray using data binding . Anyone have a solution?

Is this possible with a HierarchicalDataTemplate ?

thank

+3
source share
1 answer

While the ToolBarTray tool does not contain the ItemsSource property, it contains the ToolBars property with which you could bind. And then each toolbar has an ItemsSource property that you could contact.

So your binding will look something like this:

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

Then you can start using HierarchicalDataTemplates in toolbars:

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

All Articles