Back to Devexpress

ButtonEdit.ButtonsSource Property

wpf-devexpress-dot-xpf-dot-editors-dot-buttonedit-a0f9f5b2.md

latest8.7 KB
Original Source

ButtonEdit.ButtonsSource Property

Gets or sets a collection of objects providing information to generate and initialize buttons for the current ButtonEdit. This is a dependency property.

Namespace : DevExpress.Xpf.Editors

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

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
public IEnumerable ButtonsSource { get; set; }
vb
Public Property ButtonsSource As IEnumerable

Property Value

TypeDescription
IEnumerable

A source of objects to be visualized as buttons.

|

Remarks

The ButtonsSource property supports the MVVM design pattern. See the MVVM Framework topic to learn more.

Use the ButtonEdit.ButtonTemplate and ButtonEdit.ButtonTemplateSelector properties to visualize objects stored in the ButtonsSource collection.

Example

xaml
<dxe:ButtonEdit ButtonsSource="{Binding Items}">
    <dxe:ButtonEdit.ButtonTemplate>
        <DataTemplate>
            <ContentControl>
                <dxe:ButtonInfo Command="{Binding Command}"
                                Content="{Binding Content}"
                                IsLeft="{Binding IsLeft}"/>
            </ContentControl>
        </DataTemplate>
    </dxe:ButtonEdit.ButtonTemplate>
</dxe:ButtonEdit>
csharp
public class MainViewModel : ViewModelBase {

    private IMessageBoxService MessageBoxService { get { return GetService<IMessageBoxService>(); } }

    public ObservableCollection<ButtonViewModel> Items {
        get { return GetProperty(() => Items); }
        set { SetProperty(() => Items, value); }
    }
    public MainViewModel() {
        Items = new ObservableCollection<ButtonViewModel>() {
            new ButtonViewModel() {
                Content = "A",
                Command = new DelegateCommand(()=> {
                    MessageBoxService.ShowMessage("A");
                }),
                IsLeft = true,
            },
            new ButtonViewModel() {
                Content = "B",
                Command = new DelegateCommand(()=> {
                    MessageBoxService.ShowMessage("B");
                }),
                IsLeft = true,
            },
            new ButtonViewModel() {
                Content = "C",
                Command = new DelegateCommand(()=> {
                    MessageBoxService.ShowMessage("C");
                }),
                IsLeft = true,
            },
            new ButtonViewModel() {
                Content = "X",
                Command = new DelegateCommand(()=> {
                    MessageBoxService.ShowMessage("X");
                }),
            },
            new ButtonViewModel() {
                Content = "Y",
                Command = new DelegateCommand(()=> {
                    MessageBoxService.ShowMessage("Y");
                }),
            },
            new ButtonViewModel() {
                Content = "Z",
                Command = new DelegateCommand(()=> {
                    MessageBoxService.ShowMessage("Z");
                }),
            },
            new ButtonViewModel() {
                Content = "Clear",
                Command = new DelegateCommand(()=> {
                    this.Items.Clear();
                    Items = new ObservableCollection<ButtonViewModel>(Items);
                }),
            },
            new ButtonViewModel() {
                Content = "Add",
                Command = new DelegateCommand(()=> {
                    Items.Add(new ButtonViewModel() {
                        Content = "New",
                        IsLeft = this.Items.Count % 2 == 0
                    });
                    Items = new ObservableCollection<ButtonViewModel>(Items);
                }),
            },
        };
    }
}
vb
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
csharp
public class ButtonViewModel : ViewModelBase {
    public string Content {
        get { return GetProperty(() => Content); }
        set { SetProperty(() => Content, value); }
    }
    public ICommand Command {
        get { return GetProperty(() => Command); }
        set { SetProperty(() => Command, value); }
    }
    public bool IsLeft {
        get { return GetProperty(() => IsLeft); }
        set { SetProperty(() => IsLeft, value); }
    }
}
vb
Public Class ButtonViewModel
    Inherits ViewModelBase

    Public Property Content() As String
        Get
            Return GetProperty(Function() Content)
        End Get
        Set(ByVal value As String)
            SetProperty(Function() Content, value)
        End Set
    End Property
    Public Property Command() As ICommand
        Get
            Return GetProperty(Function() Command)
        End Get
        Set(ByVal value As ICommand)
            SetProperty(Function() Command, value)
        End Set
    End Property
    Public Property IsLeft() As Boolean
        Get
            Return GetProperty(Function() IsLeft)
        End Get
        Set(ByVal value As Boolean)
            SetProperty(Function() IsLeft, value)
        End Set
    End Property
End Class

See Also

ButtonTemplate

ButtonTemplateSelector

MVVM Framework

ButtonEdit Class

ButtonEdit Members

DevExpress.Xpf.Editors Namespace