Override the ShowEditorCommand of RadPropertyGrid
Environment
Product Version | 2022.2.621 |
Product | RadPropertyGrid for WPF |
Description
How to replace the show editor command, executed when the modal editor of the PropertyGrid is used. The modal editor is used when the EditorAttribute is used with EditorType
set to Modal
.
Solution
To replace the default action executed on modal editor button click, override the behavior of the Telerik's ModalEditor.ShowEditorCommand
.
static MainWindow()
{
CommandManager.RegisterClassCommandBinding(typeof(RadButton), new CommandBinding(ModalEditor.ShowEditorCommand, ShowEditorExecuted, CanShowEditorExecute));
}
private static void CanShowEditorExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
e.Handled = true;
}
private static void ShowEditorExecuted(object sender, ExecutedRoutedEventArgs e)
{
var button = (RadButton)sender;
var modalEditor = button.ParentOfType<ModalEditor>();
if (modalEditor != null)
{
// here you can execute a custom action, like opening of custom dialog
var window = new Window()
{
DataContext = modalEditor.DataContext,
Content = modalEditor.Editor,
SizeToContent = SizeToContent.WidthAndHeight,
Owner = Application.Current.MainWindow,
WindowStartupLocation = modalEditor.WindowStartupLocation,
Top = modalEditor.WindowTop,
Left = modalEditor.WindowLeft
};
window.ShowDialog();
}
}