Reputation: 55
First of all: I have no idea how I should describe this in the Title. So if someone has an idea for a more descriptive title, please let me know.
I am making a desktop app, where the user should be able to define (many) sets of ItemCollections. The user should also be able to define custom ItemTypes. Finally, the user should be able to attribute each Item to a specific ItemType. But an ItemCollection can contain Items of various ItemTypes. In other parts of the applications, the Items of each ItemCollection will be sorted/manipulated based on their assigned ItemType.
I have shown a rough (example) outline of my intended architecture below. How do I assign an ItemType to each Item, based on the structure shown below?
class ViewModel
{
public ViewModel()
{
ItemSets = new ObservableCollection<ItemCollection>();
ItemTypes = new ObservableCollection<ItemType>();
}
ObservableCollection<ItemCollection> ItemSets { get; set; }
ObservableCollection<ItemType> ItemTypes { get; set; }
}
class ItemCollection : ObservableCollection<Item>
{
public ItemCollection() {}
}
class ItemType
{
public ItemType() {}
public string TypeName;
public string TypeCategory;
public string OtherProperty
}
What I have done below obviously doesn't work, since this just creates a new instance of ItemType within Item, which has no relation to the collection of ItemTypes defined in the ViewModel.
class Item
{
public Item() {}
public ItemType Type; //Need to find a different way of doing this
public string Name;
public double Size;
public string OtherProperty;
}
I guess the behaviour I am trying to achieve is as if ItemTypes is an Enum. However, I can't define ItemTypes as an Enum, since it needs to be dynamic at runtime.
What is the best way to go about this? What am I missing? Thanks.
Upvotes: 0
Views: 132