Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 853111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:42:24+00:00 2026-05-15T07:42:24+00:00

I am working on wpf PropertyGrid (PG) control and I want the PG to

  • 0

I am working on wpf PropertyGrid(PG) control and I want the PG to support collection type(IList, ObservableCollection etc.) properties. I am bit confused on how to keep track of selected item(of that collection) and pass that to client.

Any ideas?

If the solution makes use of the Open Source WPF PropertyGrid (http://www.codeplex.com/wpg) I will implement the changes /additions back into the control.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:42:25+00:00Added an answer on May 15, 2026 at 7:42 am

    No answers proves that there is no straight forward way of doing this. So I implemented this feature this way –

    I created an attribute named RelatedItemSourcePropertyAttribute like this –

    /// <summary>
    /// Attribute to identify the related item source property.
    /// Note: Property should be of IEnumerable type
    /// </summary>
    [global::System.AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = false)]
    public sealed class RelatedItemSourcePropertyAttribute : Attribute
    {
        // See the attribute guidelines at 
        //  http://go.microsoft.com/fwlink/?LinkId=85236
    
        private string relatedPropertyName;
        public static readonly RelatedItemSourcePropertyAttribute Default = new RelatedItemSourcePropertyAttribute(string.Empty);
    
        /// <summary>
        /// Initializes a new instance of the <see cref="RelatedPropertyAttribute"/> class.
        /// </summary>
        /// <param name="relatedPropertyName">Name of the related property.</param>
        public RelatedItemSourcePropertyAttribute(string relatedPropertyName)
        {
            this.relatedPropertyName = relatedPropertyName;
        }
    
        /// <summary>
        /// Gets a value indicating whether [related property name].
        /// </summary>
        /// <value><c>true</c> if [related property name]; otherwise, <c>false</c>.</value>
        public string RelatedPropertyName
        {
            get { return relatedPropertyName; }
        }
    
        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        ///     <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (!(obj is RelatedItemSourcePropertyAttribute))
                return false;
            if (obj == this)
                return true;
            return ((RelatedItemSourcePropertyAttribute)obj).relatedPropertyName == relatedPropertyName;
        }
    
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return relatedPropertyName.GetHashCode();
        }
    
        /// <summary>
        /// When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.
        /// </summary>
        /// <returns>
        /// true if this instance is the default attribute for the class; otherwise, false.
        /// </returns>
        public override bool IsDefaultAttribute()
        {
            return relatedPropertyName == RelatedItemSourcePropertyAttribute.Default.relatedPropertyName;
        }
    }
    

    this attribute will take the property name of the related item source property(whose value will be used to fill the dropdown). It will be used like this –

        [RelatedItemSourceProperty("UnitNames")]
        public virtual string SelectedUnit
        {
            get { return (string)GetValue(SelectedUnitProperty); }
            set { SetValue(SelectedUnitProperty, value); }
        }
        public static readonly DependencyProperty SelectedUnitProperty =
            DependencyProperty.Register("SelectedUnit", typeof(string), typeof(BaseControl),
            new UIPropertyMetadata(string.Empty, new PropertyChangedCallback(SelectedUnitChangedCallBack)));
    
    
        public virtual ObservableCollection<string> UnitNames
        {
            get { return (ObservableCollection<string>)GetValue(UnitNamesProperty); }
            set { SetValue(UnitNamesProperty, value); }
        }
        public static readonly DependencyProperty UnitNamesProperty =
            DependencyProperty.Register("UnitNames", typeof(ObservableCollection<string>),
            typeof(BaseProperties), new PropertyMetadata(null)); //Validation
    

    and then in property I binded the related item source property with the combobox.

    Hope to see a better solution then this 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with WPF. I want to create keyboard shortcuts for my WPF
i am working with wpf media element.i want to change the media element source
I am working on WPF app and I want to get news feed using
Working in WPF, writing a custom user control. I am trying to change the
Hello Guys I am working WPF app and I want to retrive all the
I am working on WPF application and I want to retrieve News Feed using
I am working with WPF and C#. I want to fire an event when
I m working with WPF DataGrid and I want to retrieve a DataGridCell 's
I am working with WPF application and I want to assign a value of
Working with WPF it is good practice to keep your xaml.cs code behind files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.