title | description | type | page_title | slug | tags | res_type | ticketid |
---|---|---|---|---|---|---|---|
Hiding Add and Remove Buttons in CollectionEditor for WPF |
Learn how to hide the Add and Remove buttons in the CollectionEditor part of RadPropertyGrid. |
how-to |
How to Hide CollectionEditor Add New and Delete Buttons in WPF |
kb-collection-editor-hide-add-remove-buttons |
collectioneditor, wpf, collectioneditor, visibility, buttons |
kb |
1682419 |
Product | CollectionEditor for WPF |
How to hide the Add and Remove buttons in the CollectionEditor control (part of RadPropertyGrid).
On Loaded
of CollectionEditor, set use the [ChildrenOfType extension method]({%slug common-visual-tree-helpers%}) to get the buttons and set their Visibility
to Collapsed
.
private void CollectionEditor_Loaded(object sender, RoutedEventArgs e)
{
var editor = (CollectionEditor)sender;
var addButton = editor.ChildrenOfType<RadButton>().FirstOrDefault(x => x.Command == CollectionEditorCommands.AddNew);
if (addButton != null)
{
addButton.Visibility = Visibility.Collapsed;
}
var removeButton = editor.ChildrenOfType<RadButton>().FirstOrDefault(x => x.Command == CollectionEditorCommands.Delete);
if (removeButton != null)
{
removeButton.Visibility = Visibility.Collapsed;
}
}