Skip to main content

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.v23.2.dll

NuGet Package: DevExpress.Wpf.Core

Declaration

public IEnumerable ButtonsSource { get; set; }

Property Value

Type Description
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

<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>
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);
                }),
            },
        };
    }
}
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); }
    }
}
See Also