Selecting from a list of options when the property is dynamically generated

5 posts, 0 answers
  1. James
    James avatar
    3 posts
    Member since:
    Jan 2012

    Posted 16 Oct 2012 Link to this post

    I am binding my RadPropertyGrid to an object that contains a "property bag" - in other words, the object has a collection of child objects that represent the properties displayed in the property grid.  This collection is populated from a database so there is no knowledge at all in the application of the names, values, etc. for any of the 'properties'.

    The object subclasses CustomTypeDescriptor, overrides GetProperties and returns a custom PropertyDescriptor for each of the items in the collection.  All of this works great except for cases where I need the user to select from a list of options.  Note that the list of options is NOT an enumeration but a collection of name/value pairs obtained from the database.

    So the question is how to display a combobox in the property grid that is bound dynamically?

    I've seen the other forum posts and examples using the LookupPropertyDefinition but they all use static references in the XAML to the property names and use static resources as the ItemsSource.  Neither of these are possible in my case as I won't know which 'properties' have options until runtime as the list is configurable in the database.  In addition, the list of choices is pulled out of the database so it will be different for each 'property'.

    In previous incarnations of our application, we've been able to simply define a custom TypeConverter for the property, override the GetStandardValuesSupported method to return true then override GetStandardValues which would return the list of choices.  As I have learned from other posts, this is not supported in the RadPropertyGrid.  So what is?

    Your help is greatly appreciated as this is a significant enough feature and enough time has been spent trying to get it working that it could lead us to another vendor that is capable of supporting this need.
  2. Scott
    Scott avatar
    8 posts
    Member since:
    Aug 2011

    Posted 17 Oct 2012 Link to this post

    Update on my Colleague and my issue.


    In the Xaml when implementing the following code:

    <UserControl
    .
    .
    .
    .
    xmlns:propertyGrid="clr-namespace:Telerik.Windows.Controls.Data.PropertyGrid;assembly=Telerik.Windows.Controls.Data"
    .
    .
    .
    >
     
    <UserControl.Resources>
                <local:PropertyGridDataTemplateSelector.OtherDataTemplate>
                    <DataTemplate DataType="settings:SettingOptionInfoCollection">
                        <ComboBox
                                  propertyGrid:AutoBindBehavior.UpdateBindingOnElementLoaded="ItemsSource"
                                  SelectedValue="{Binding Path=SelectedOption, Mode=TwoWay}"
                                  />
                    </DataTemplate>
                </local:PropertyGridDataTemplateSelector.OtherDataTemplate>
            </local:PropertyGridDataTemplateSelector>
        </UserControl.Resources>
         
        <Grid>
            <telerik:RadBusyIndicator IsBusy="{Binding IsBusy}" >
                <telerik:RadPropertyGrid Item="{Binding Items}" EditorTemplateSelector="{StaticResource dataTemplateSelector}" />
            </telerik:RadBusyIndicator>
        </Grid>
    </UserControl>

    We are binding to a Property bag object that subclasses CustomTypeDescriptor, overrides GetProperties and returns a custom PropertyDescriptor for each of the items in the collection.  When we have a combo box we return a custom collection of options which populates the combo box items, but when it comes to using the SelectedOption of that collection to bind to the Selected Value of the Combo Box.

    Example of the collection:

    public class SettingOptionInfoCollection : ObservableCollection<SettingOptionInfo>
    {
        private SettingOptionInfo _selectedOption;
     
        public SettingOptionInfoCollection()
        {
        }
     
        public SettingOptionInfo SelectedOption
        {
            get
            {
                return _selectedOption;
            }
            set
            {
                _selectedOption = value;
                OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("SelectedOption"));
            }
        }

    The problem is that when the ItemSource is set to:

    propertyGrid:AutoBindBehavior.UpdateBindingOnElementLoaded="ItemsSource"

    We assumed that the datacontext would set to the binding property of the itemsource being or collection.  Instead it seems that the datacontext is forced set to our "property bag" object that does not have a property called SelectedOptions.  The datacontext of the combobox at this point needs to be that of our itemsource property, from the PropertyGrid, can you help provide some insight on how we can access that binding item from the BindingSource to set our selected item?

    Everything works great except for binding the SelectedOption to the SelectedValue property.  Any help would be greatly appreciated.

    Current the Binding Path expectes the SelectedOption to be a part of our "Property Bag" Object.

    Let me know if you have any questions or don't understand what we are doing.

    Thanks,
    -Scott

  3. UI for WPF is Visual Studio 2017 Ready
  4. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 19 Oct 2012 Link to this post

    Hi Scott,

    Thank you for providing us those clarifications. We will need a bit more time to mimic this behavior on our side. I will contact you back on Monday to share the results of our research.

    Greetings,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Scott
    Scott avatar
    8 posts
    Member since:
    Aug 2011

    Posted 22 Oct 2012 Link to this post

    Thanks for getting back Ivan.

    I have uploaded an example program that demonstrates our issue to the support ticket system.  The support ticket ID for this issue is 620579.

    Please let me know that you got the zipped program and what you find out.

    Thanks,
    -Scott
  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 22 Oct 2012 Link to this post

    Hi Scott,

    Thank you for the attached project. Unfortunately the behavior that you are currently experiencing is actually the default one for RadPropertyGrid. As RadPropertyGrid serves as a property editor and visualizer for CLR objects, scenarios when a single option should be chosen as a value of a certain property are quite common. So that, it seems natural that a ComboBox's SelectedValue should be bound to the respective item's property. On the other hand the set of possible options does not really belong to the BusinessObject's domain. Another reason not to set a ComboBox's DataContext to be the ItemsSource would be the need to create custom collection types that expose additional properties (like in your scenario). Personally, I would encourage you to change your architecture a bit and move the SelectedOption property to your BusinessObject and optionally, the OptionsCollection property - to the ViewModel.

    Greetings,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready