This is a migrated thread and some comments may be shown as answers.

RadPropertyGrid problem with EditorTemplate in Single EditMode

1 Answer 110 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Eugene
Top achievements
Rank 1
Eugene asked on 14 Oct 2016, 02:09 PM

In my project I use RadPropertyGrid. I can't set custom editors in xaml because I don't know properties of PropertyGrid.Item in design mode.
I defined PropertyDefinition and set EditorTemplate in run time.

<DataTemplate x:Name="CustomComboBox">
   <ComboBox telerik:AutoBindBehavior.UpdateBindingOnElementLoaded="SelectedValue" SelectionMode="Single" Loaded="ComboBox_Loaded"/>
</DataTemplate>

I have dynamically set some properties of Editors in Loaded() event (for example ItemsSource for ComboBox).

I use PropertyGridField.AutoGeneratedPath to define witch editor is loading.

private void ComboBox_Loaded(object sender, RoutedEventArgs e)
{
   string propertyName = ((PropertyDefinition)((PropertyGridField)((ComboBox)sender).Parent).DataContext).AutoGeneratedPath;
   //creating itemsList...
   ((ComboBox)sender).ItemsSource = itemsList;
   ((ComboBox)sender).DisplayMemberPath = "DisplayName";
   ((ComboBox)sender).SelectedValuePath = "Code";
}

In EditMode="Default" it works fine.

If I set EditMode to Single this solution will not work.

In Loaded() event sender.Parent = null.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 19 Oct 2016, 11:01 AM
Hello Sergei,

Here is an alternative approach for getting the bound property which will work in both edit modes:

var comboBox = sender as ComboBox;
var pd = comboBox.ParentOfType<PropertyGridField>().DataContext as PropertyDefinition;
var propertyName = pd.AutoGeneratedPath;

Please let me know if this would work for you. If that is not the case, please provide more details regarding you exact requirements and I will gladly guide you further in finding a solution for your particular scenario.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
PropertyGrid
Asked by
Eugene
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or