I have several User Controls in a project, and one of them retrieves items from an XML, creates objects of the type "ClassItem" and should notify the other UserControl information about those items.
I have created a class for my object (the "model" all items will have):
public class ClassItem
{
public int Id { get; set; }
public string Type { get; set; }
}
I have another class that is used to notify the other User Controls when an object of the type "ClassItem" is created:
public class Class2: INotifyPropertyChanged
{
// Properties
public ObservableCollection<ClassItem> ItemsCollection { get; internal set; }
// Events
public event PropertyChangedEventHandler PropertyChanged;
// Methods
public void ShowItems()
{
ItemsCollection = new ObservableCollection<ClassItem>();
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("ItemsCollection"));
}
}
}
The data comes from an XML file that is parsed in order to create the objects of type ClassItem:
void DisplayItems(string xmlContent)
{
XDocument xmlItems = XDocument.Parse(xmlContent);
var items = from item in xmlItems.Descendants("item")
select new ClassItem{
Id = (int)item.Element("id"),
Type = (string)item.Element("type)
};
}
If I'm not mistaken, this is supposed to parse the xml and create a ClassItem object for each item it finds in the XML. Hence, each time a new ClassItem object is created, this should fire the Notifications for all the UserControls that are "bind" to the "ItemsCollection" notifications defined in Class2.
Yet the code in Class2 doesn't even seem to be run :-( and there are no notifications of course...
Am I mistaken in any of the assumptions I've done, or am I missing something? Any help would be appreciated!
Thx!