Skip to main content
A newer version of this page is available. .

ButtonEdit.ButtonTemplate Property

Gets or sets the data template used to render buttons of the current ButtonEdit.

Namespace: DevExpress.Xpf.Editors

Assembly: DevExpress.Xpf.Core.v19.1.dll

Declaration

public DataTemplate ButtonTemplate { get; set; }

Property Value

Type Description
DataTemplate

A DataTemplate object that is used to render buttons of the current ButtonEdit.

Remarks

The ButtonTemplate property specifies the data template used to render buttons from the ButtonEdit.ButtonsSource collection.

<dxe:ButtonEdit.ButtonTemplate>
    <DataTemplate>
        <ContentControl>
            <dxe:ButtonInfo 
                Command="{Binding Command}"
                Content="{Binding Content}"
                IsLeft="{Binding IsLeft}" />
        </ContentControl>
    </DataTemplate>
</dxe:ButtonEdit.ButtonTemplate>

If you want to declare several data templates and apply one of them according to your own logic, use the ButtonEdit.ButtonTemplateSelector property.

Example

Imports DevExpress.Mvvm
Imports System.Collections.ObjectModel

Namespace DXSample.ViewModels
    Public Class MainViewModel
        Inherits ViewModelBase

        Private ReadOnly Property MessageBoxService() As IMessageBoxService
            Get
                Return GetService(Of IMessageBoxService)()
            End Get
        End Property

        Public Property Items() As ObservableCollection(Of ButtonViewModel)
            Get
                Return GetProperty(Function() Items)
            End Get
            Set(ByVal value As ObservableCollection(Of ButtonViewModel))
                SetProperty(Function() Items, value)
            End Set
        End Property
        Public Sub New()
            Items = New ObservableCollection(Of ButtonViewModel)() From {
                New ButtonViewModel() With {
                    .Content = "A",
                    .Command = New DelegateCommand(Function() MessageBoxService.ShowMessage("A")),
                    .IsLeft = True
                },
                New ButtonViewModel() With {
                    .Content = "B",
                    .Command = New DelegateCommand(Function() MessageBoxService.ShowMessage("B")),
                    .IsLeft = True},
                New ButtonViewModel() With {
                    .Content = "C",
                    .Command = New DelegateCommand(Function() MessageBoxService.ShowMessage("C")),
                    .IsLeft = True},
                New ButtonViewModel() With {
                    .Content = "X",
                    .Command = New DelegateCommand(Function() MessageBoxService.ShowMessage("X"))
                },
                New ButtonViewModel() With {
                    .Content = "Y",
                    .Command = New DelegateCommand(Function() MessageBoxService.ShowMessage("Y"))},
                New ButtonViewModel() With {
                    .Content = "Z",
                    .Command = New DelegateCommand(Function() MessageBoxService.ShowMessage("Z"))},
                New ButtonViewModel() With {
                    .Content = "Clear",
                    .Command = New DelegateCommand(
                        Sub()
                            Items.Clear()
                            Items = New ObservableCollection(Of ButtonViewModel)(Items)
                        End Sub)
                },
                New ButtonViewModel() With {
                    .Content = "Add",
                    .Command = New DelegateCommand(
                        Sub()
                            Items.Add(New ButtonViewModel() With {
                                .Content = "New",
                                .IsLeft = Items.Count Mod 2 = 0
                            })
                            Items = New ObservableCollection(Of ButtonViewModel)(Items)
                        End Sub)
                }
            }
        End Sub
    End Class
End Namespace
See Also