This example uses the BarLinkContainerItem
property to group related bar items and reuse them across different containers.
Use this technique when you need to:
- Define a set of commands (such as
Cut
,Copy
, andPaste
) once and reuse them in multiple locations (for example, in a bar or a submenu). - Keep your
BarManager
layout consistent and avoid duplicating command definitions. - Dynamically extend or reorganize bar content without redefining individual item links.
This solution simplifies maintenance and improves clarity when you work with toolbars that include common command groups.
The example defines five BarButtonItem
objects that correspond to common edit operations:
<dxb:BarButtonItem x:Name="itemCut" Content="Cut" />
<dxb:BarButtonItem x:Name="itemCopy" Content="Copy" />
<dxb:BarButtonItem x:Name="itemPaste" Content="Paste" />
<dxb:BarButtonItem x:Name="itemUndo" Content="Undo" />
<dxb:BarButtonItem x:Name="itemRedo" Content="Redo" />
Use the BarLinkContainerItem
property to group Cut
, Copy
, and Paste
commands into a single reusable unit. This container holds links to existing BarButtonItem
elements:
<dxb:BarLinkContainerItem x:Name="linkContainerItem1" Content="Edit Commands">
<dxb:BarLinkContainerItem.ItemLinks>
<dxb:BarButtonItemLink BarItemName="itemCut" />
<dxb:BarButtonItemLink BarItemName="itemCopy" />
<dxb:BarButtonItemLink BarItemName="itemPaste" />
</dxb:BarLinkContainerItem.ItemLinks>
</dxb:BarLinkContainerItem>
You can reuse the container in a BarSubItem
, which acts as a submenu in the UI:
<dxb:BarSubItem Content="Edit" x:Name="subMenu1">
<dxb:BarSubItem.ItemLinks>
<dxb:BarLinkContainerItemLink BarItemName="linkContainerItem1" />
</dxb:BarSubItem.ItemLinks>
</dxb:BarSubItem>
The following code example defines a top-level bar and adds both the container and the submenu, along with separators and additional items:
<dxb:Bar x:Name="bar1" Caption="Bar 1">
<dxb:Bar.ItemLinks>
<dxb:BarLinkContainerItemLink BarItemName="linkContainerItem1" />
<dxb:BarItemLinkSeparator />
<dxb:BarButtonItemLink BarItemName="itemUndo" />
<dxb:BarButtonItemLink BarItemName="itemRedo" />
<dxb:BarItemLinkSeparator />
<dxb:BarSubItemLink BarItemName="subMenu1" />
</dxb:Bar.ItemLinks>
</dxb:Bar>
- Window1.xaml (VB: Window1.xaml)
- Window1.xaml.cs (VB: Window1.xaml.vb)
- WPF Bars - Use Separators to Group Bar Item Links
- MVVM Application with WPF Bars
- WPF PDF Viewer - Customize the Integrated Bar's Commands
- WPF MVVM Behaviors - Display Theme Selectors Based on BarItems and Hide Themes from List
- WPF Dock Layout Manager - Merge Bars in Controls That Support Automatic Merging
(you will be redirected to DevExpress.com to submit your response)