Back to Devexpress

BarButtonItem Class

wpf-devexpress-dot-xpf-dot-bars-d7b4eb3c.md

latest9.0 KB
Original Source

BarButtonItem Class

Represents a bar button item.

Namespace : DevExpress.Xpf.Bars

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public class BarButtonItem :
    BarItem
vb
Public Class BarButtonItem
    Inherits BarItem

Remarks

Use this item to add a regular button to bars and menus.

Clicking a button invokes the BarItem.ItemClick and BarManager.ItemClick events. In addition, if a command is assigned to the BarItem.Command property, it’s invoked as well.

The item’s functionality can also be invoked by pressing the shortcut specified by the BarItem.KeyGesture property.

Example

This example shows how to create bar button items (BarButtonItem objects) and add a link separator between them. The separator is created using the BarItemLinkSeparator class.

The following image shows the result:

View Example

xaml
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" 
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
        x:Class="BarItemLinkSeparatorEx.Window1" 
        Title="Window1" Height="300" Width="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <dxb:BarContainerControl Grid.Row="0">
            <dxb:ToolBarControl Caption="Main Toolbar" BarItemHorizontalIndent="10">
                <dxb:BarButtonItem Content="Undo" Glyph="{dx:DXImage Image=undo16x16.png}" ItemClick="itemClick"/>
                <dxb:BarButtonItem Content="Redo" Glyph="{dx:DXImage Image=redo16x16.png}" ItemClick="itemClick"/>
                <dxb:BarItemLinkSeparator />
                <dxb:BarButtonItem Content="Copy" Glyph="{dx:DXImage Image=copy16x16.png}" ItemClick="itemClick"/>
                <dxb:BarButtonItem Content="Paste" Glyph="{dx:DXImage Image=paste16x16.png}" ItemClick="itemClick"/>
            </dxb:ToolBarControl>
        </dxb:BarContainerControl>

        <RichTextBox Grid.Row="1"/>

    </Grid>
</Window>
csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BarItemLinkSeparatorEx {
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
        }

        // Respond to clicking the bar items
        private void itemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
            MessageBox.Show("Item " + e.Item.Content + " has been clicked.");
        }

    }
}
vb
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes

Namespace BarItemLinkSeparatorEx
    ''' <summary>
    ''' Interaction logic for Window1.xaml
    ''' </summary>
    Partial Public Class Window1
        Inherits Window

        Public Sub New()
            InitializeComponent()
        End Sub

        ' Respond to clicking the bar items
        Private Sub itemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
            MessageBox.Show("Item " & e.Item.Content & " has been clicked.")
        End Sub

    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the BarButtonItem class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-spreadsheet-bind-spreadsheet-to-ms-sql-server-database/CS/WpfSpreadsheet_BindToDataSource/MainWindow.xaml#L21

xml
<dxb:BarManager.Items>
    <dxb:BarButtonItem x:Name="biFileNew" Command="{Binding FileNew, Mode=OneTime, Source={StaticResource commands}}" />
    <dxb:BarButtonItem x:Name="biFileOpen" Command="{Binding FileOpen, Mode=OneTime, Source={StaticResource commands}}" />

wpf-spreadsheet-assign-custom-in-place-editors/CS/WpfSpreadsheet_CustomCellEditors/MainWindow.xaml#L22

xml
<dxb:BarManager.Items>
    <dxb:BarButtonItem x:Name="biFileNew" Command="{Binding FileNew, Mode=OneTime, Source={StaticResource commands}}" />
    <dxb:BarButtonItem x:Name="biFileOpen" Command="{Binding FileOpen, Mode=OneTime, Source={StaticResource commands}}" />

wpf-spreadsheet-bind-a-worksheet-to-generic-list-or-bindinglist-data-source/CS/DataBindingToListExample/MainWindow.xaml#L16

xml
<dxb:BarManager.Items>
    <dxb:BarButtonItem x:Name="biFileNew" Command="{Binding FileNew, Mode=OneTime, Source={StaticResource commands}}"/>
    <dxb:BarButtonItem x:Name="biFileOpen" Command="{Binding FileOpen, Mode=OneTime, Source={StaticResource commands}}"/>

wpf-data-grid-implement-crud-operations/CS/CodeBehind/EFCore/LocalData/MainWindow.xaml#L14

xml
<dxb:ToolBarControl>
    <dxb:BarButtonItem Content="Refresh (F5)" Command="{Binding View.Commands.RefreshDataSource, ElementName=grid}"
                       Glyph="{dx:DXImage SvgImages/Icon Builder/Actions_Refresh.svg}" BarItemDisplayMode="ContentAndGlyph" />

wpf-docklayoutmanager-merge-ribbon-controls/CS/WpfApplication1/MainWindow.xaml#L12

xml
<dxr:RibbonPageGroup Caption="File">
    <dxb:BarButtonItem x:Name="biNew" Content="New" LargeGlyph="{dx:DXImage Image=New_32x32.png}"/>
    <dxb:BarButtonItem x:Name="biOpen" Content="Open" Glyph="{dx:DXImage Image=Open_16x16.png}"/>

Implements

IControllerAction

Inheritance

Show 11 items

Object DispatcherObject DependencyObject ContentElement FrameworkContentElement BarItem BarButtonItem BarCheckItem

BarSplitButtonItem

BarSubItem

BarSplitCheckItem

See Also

BarButtonItem Members

Items and Links

DevExpress.Xpf.Bars Namespace