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.v24.1.dll
NuGet Package: DevExpress.Wpf.Core
Declaration
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.
If you want to declare several data templates and apply one of them according to your own logic, use the ButtonEdit.ButtonTemplateSelector property.
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