ComboBox in PropertyGrid is empty

2 posts, 0 answers
  1. Isabel
    Isabel avatar
    2 posts
    Member since:
    Jan 2015

    Posted 15 Jan 2015 Link to this post

    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. Isabel
    Isabel avatar
    2 posts
    Member since:
    Jan 2015

    Posted 16 Jan 2015 in reply to Isabel Link to this post

    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>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top