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 5972365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:38:51+00:00 2026-05-22T20:38:51+00:00

UPDATED I am updating this post because I did some more reading and decided

  • 0

UPDATED

I am updating this post because I did some more reading and decided to re-implement my solution.

Original Problem: I have a class with static properties and one Property that is a dynamic collection of properties (via a dictionary). I want to databind my class to a wpf datagrid where each static property should be a column and each dictionary entry should be a column in the grid.

After doing some more research, I decided to implement a PropertyBag class that will contain my Dictionary of properties and values. Almost everything is working now. I have my grid being displayed with all the correct columns and the static property values are being applied correctly.

However, now I am not able to get any of the values from the dictionary to be applied to the grid, and I am not sure where to go from here.

More info:

My database has 3 tables, a plate, a category, and a categoryplateassociation table. Each plate can have 0 to many categories. For now, I am populating each plate with all the categories and setting the strings to empty. Then, when an association is returned (between a plate and category), I am setting the real value on the specific category name. This all happens before the grid is created.

Property Bag:

public class PropertyBag
{
    private readonly Dictionary<string, string> values = new Dictionary<string, string>();

    public string this[string key]
    {
        get 
        {
            string value;
            values.TryGetValue(key, out value);
            return value;
        }
        set
        {
            if (value == null) values.Remove(key);
            else values[key] = value;
        }
    }
}

Revised Plate class

[TypeDescriptionProvider(typeof(PlateTypeDescriptionProvider))]
public class Plate : INotifyPropertyChanged
{
    public int ID;
    private string name;
    private string status;
    private string creator;
    private Uri location;
    private string description;

    public Plate()
    {
        CustomCategories = new PropertyBag();
    }

    public PropertyBag CustomCategories { get; set; }

    public string Name
    {
        get { return name;}
        set
        {
            name = value;
            NotifyPropertyChanged("Name");
        }
    }

    public string Status
    {
        get { return status; }
        set
        {
            status = value;
            NotifyPropertyChanged("Status");
        }
    }

    public string Creator
    {
        get { return creator; }
        set
        {
            creator = value;
            NotifyPropertyChanged("Creator");
        }
    }

    public Uri Location
    {
        get { return location; }
        set
        {
            location = value;
            NotifyPropertyChanged("Location");
        }
    }

    public string Description
    {
        get { return description; }
        set
        {
            description = value;
            NotifyPropertyChanged("Description");
        }
    }

    public static Plate ConvertDataPlateToBusinessPlate(TestPlate dataPlate)
    {
        var plate = new Plate
                        {
                            Name = dataPlate.Name, 
                            Status = dataPlate.Status,
                            Creator = dataPlate.Creator, 
                            Description = dataPlate.Description, 
                            Location = new Uri(dataPlate.Location)
                        };
        return plate;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

Revised CustomTypeDescriptor:

public override PropertyDescriptorCollection GetProperties()
    {
        return GetProperties(null);
    }

    public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
    {
        var properties = new ArrayList();
        foreach (PropertyDescriptor propertyDescriptor in base.GetProperties(attributes))
        {
            if(propertyDescriptor.PropertyType.Equals(typeof(PropertyBag)))
            {
                //Static list of all category names
                var categoryNames = Categories.GetAll();
                foreach (var categoryName in categoryNames)
                {
                    properties.Add(new PropertyBagPropertyDescriptor(categoryName));
                }
            }
            else
            {
                properties.Add(propertyDescriptor);
            }

        }
        var props = (PropertyDescriptor[])properties.ToArray(typeof(PropertyDescriptor));
        return new PropertyDescriptorCollection(props);
    }

Revised PropertyDescriptor

    public class PropertyBagPropertyDescriptor : PropertyDescriptor
{
    public PropertyBagPropertyDescriptor(string name) : base(name, null)
    {}

    public override bool CanResetValue(object component)
    {
        return true;
    }

    public override object GetValue(object component)
    {
        return ((PropertyBag) component)[Name];
    }

    public override void ResetValue(object component)
    {
        ((PropertyBag)component)[Name] = null;
    }

    public override void SetValue(object component, object value)
    {
        ((PropertyBag) component)[Name] = (string) value;
    }

    public override bool ShouldSerializeValue(object component)
    {
        return ((PropertyBag)component)[Name] != null;
    }

    public override Type ComponentType
    {
        get { return typeof(PropertyBag); }
    }

    public override bool IsReadOnly
    {
        get { return false; }
    }

    public override Type PropertyType
    {
        get { return typeof(string); }
    }
}

simple ViewModel

 public TestPlateAdministratorViewModel()
    {
        CommandAggregator = new TestPlateAdministratorCommandAggregator(this);
        LoadData();
    }

    public static TestPlateAdministratorCommandAggregator CommandAggregator { get; set; }
    public ObservableCollection<Plate> TestPlates{ get; set; }

    private static void LoadData()
    {
        CommandAggregator.LoadPlatesCommand.Execute(null);
        CommandAggregator.LoadCategoriesCommand.Execute(null);
    }
}
  • 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-22T20:38:51+00:00Added an answer on May 22, 2026 at 8:38 pm

    does your Dictionary in your PropertyBag has a fixed size or does the keys are known?

    you did not post your xaml for your datagrid, but the binding from the propertybag to one column could look like this:

    <DataGridTextColumn Header="Col4TestKey" Binding="{Binding CustomCategories[test]}"/>
    

    i really dont know wether your PropertyBag setter will work with binding. all in all this just would work if you have a know set of keys for your dictionary.

    btw, i use flat datatables in my projects for such dynamic stuff, there are really easy to handle.

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

Sidebar

Related Questions

I am updating this post with what I think I now know about getting
I have several update methods in a javascript file, used for updating my ajax
I have a routine which is updating my business entity. The update involves about
UPDATED: Added one more question (Question #4). Hi all, I'm building myself a custom
I have a JPA domain entity that I'm updating from user input. Depending on
This is my first attempt at adding ajax to a WordPress plugin. I have
I have Post and Comment model. I want to achieve the following: Each time
Using PHP, and MySql, I am trying to implement this rather snazzy in-place editor
I have a MySQL 5 database that is updated every 5 minutes from a
Update I've updated this question to include source code of a Java implementation, using

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.