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

ComboBox in PropertyGrid is empty

2 Answers 175 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Isabel
Top achievements
Rank 1
Isabel asked on 15 Jan 2015, 04:03 PM
I've created a small application with a View and ViewModel.

In the view a PropertyGrid is used it  edit the properties from the ViewModel based on data annotations.

The ViewModel contains two properties:
    “SelectedBrand”            - the currently selected brand
    “Brands”                        - a list of all available brands.

The PropertyGrid should provide a ComboBox to edit the “SelectedBrand” and should hide the “Brands”.

So I’ve annotated “Brands”  with a “Browsable(false)” and “SelectedBrand” with a “Editor(typeof(RadComboBox))” attribute.

This works so far quite well.

Now here’s the catch: How do I tell the editor, that the “Brands” should be used as ItemsSource for  the ComboBox ?

Right now the combo box is just empty.

Thanksin advance

2 Answers, 1 is accepted

Sort by
0
Isabel
Top achievements
Rank 1
answered on 16 Jan 2015, 07:19 AM
ViewModel:

private string _selectedType;
        /// <summary>Gets or sets the type of the selected.</summary>
        /// <value>The type of the selected.</value>
        //[Attribute("Types")
        [Telerik.Windows.Controls.Data.PropertyGrid.Editor(typeof(RadComboBox))]
        public string SelectedType
        {
            get
            {
                return this._selectedType;
            }
            set
            {
                this._selectedType = value;
                this.OnPropertyChanged(() => this.SelectedType);
            }
        }
        /// <summary>Gets or sets the types.</summary>
        /// <value>The types.</value>
        [Browsable(false)]
        public IEnumerable<string> Types
        {
            get
            {
                yield return "AUDI";
                yield return "BMW";
                yield return "VW";
            }
        }

View:

<StackPanel>
        <TextBlock Text="SelectedTypes:"/>
        <TextBlock Margin="5,2" Text="{Binding SelectedType, TargetNullValue='--'}" />
        <TextBlock Text="Types:" FontWeight="Bold"/>
        <ItemsControl ItemsSource="{Binding Types}"></ItemsControl>
    </StackPanel>
0
Stefan
Telerik team
answered on 16 Jan 2015, 03:32 PM
Hi Isabel,

I recommend you to acquaint yourself more about the MVVM pattern. You can check out this and this article on this topic. In short, it's not correct your ViewModel to have presentation logic, like in your case.

I would also advise you to read our documentation on the Editor Attribute. It's main purpose is to set it on the properties of your business models.

As for your question, it won't be felicitous to use the Editor Attribute for ComboBox control, as there is no way to handle the SelectedItem property with it.

Best Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
PropertyGrid
Asked by
Isabel
Top achievements
Rank 1
Answers by
Isabel
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or