Skip to content

DevExpress-Examples/wpf-bars-create-baritem-link-container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Bars - Create a Container for BarItem Links

This example uses the BarLinkContainerItem property to group related bar items and reuse them across different containers.

Container for BarItem Links

Use this technique when you need to:

  • Define a set of commands (such as Cut, Copy, and Paste) 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.

Implementation Details

Bar Items

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" />

Group Commands in a BarLinkContainerItem

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>

Reuse the Container in a Submenu

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>

Display Items in a Toolbar

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>

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Creates a container for BarItem links and adds it to the toolbar and drop-down menu.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5