VB.NET - MVVM notify parent object of change VB

Asked By Brian Risley on 02-Mar-11 02:04 PM
I have a collection of a class object in my vm that is mapped/databound to my xaml using the reference in the collection.  I need to know when a user makes a change to the child row in the collection at the main viewmodel level.
I have looked at multiple different methods, but have not found a clean VB based method to do this that I can follow.  None of the C# routines I found converted easily for me to work with.
Basic design.  Detail class has information of fields to display along with existing/new values and other classes that are used by usercontrols that have their own methods that may return data that needs to go to the detail class.  There is a collection of the detail class in the VM class.  I have no problem with the individual detail class being aware of when it changes, but I need it to know when one of its childclasses changes values and I need the VM to know when a child detail class has changed so I can properly set controls that the XAML uses for enabling/disabling features.
Any working VB example would be appreciated.
Brian

Couple of questions

Robbe Morris replied to Brian Risley on 02-Mar-11 06:25 PM
Is this an ObservableCollection?

Are you raising the PropertyChanged event for each property on the class that implement the INotifyPropertyChanged interface?

If you are doing these, then it should be simple enough to wire up events in your property handlers for each row in the collection.

Not 100% sure of your layout but you should be able to bind to those specific UI properties that would change when values change in the collection.  You are not restricted to just binding to data display values.  You might want to create some IValueConverters that look at your internal data and then return values applicable to a UI setting such as enabled/disabled or visible/hidden type of stuff.
Brian Risley replied to Brian Risley on 02-Mar-11 06:50 PM
Rob,
Yes, it is an observable collection.  All setters raise propertychanged events.  The collection is an array of an class that contains fields/titles that are bound to the view.  No problem with the binding and getting events back to the detail class.   All our xaml is dynamic and there is no code behind!
Let me map it out.
DC = Detail class with properties for field title/field value (and other stuff, including a class that has an observable collection in it for itemlist population)
(I use array and collection meaning the same thing, an observable collection.) 
VM  View Model, it has a property that is an array of the DC class.  VM has properties that control other aspects of the view such as being able to save, change rows in a datagrid.
V View  This has a section bound to the VM that has a datagrid and a grid representing the selected row in the datagrid.
The grid labels/textboxes and other controls are bound to the dc[x] properties.

What I need to understand is when I change dc[1]'s value, I need to check in the setter if the value passed is different than the original value in the dc array element and if so, set another property to indicate that.  Then what I want is to have the VM know to execute a routine to check the indicator property for all rows in the array and set or clear a flag on the VM to indicate that the detail is different.  I will then use this flag in xaml controls to determine if I need to change the display.  I do not want xaml always checking through the children, only when a change occurs should the children be checked, so the xaml event to determine things will only look at the single VM property.  It turns out that in the itemlist object, I have properties/events bound to the xaml that are based solely on that individual itemlist, and when certain events happen such as a repopulation of the itemlist's collection, I need to let the DC know about it and it may notify the VM about it too.

I have seen example with people using their own frameworks and stuff, but not something straightforward in VB where I can grasp what is happening and how to utilize it with the different possible scenarios.  Overriding is possible, but I need it clearly explained, as I am a noob!
I am looking for something where the detail class would not have to know specifically about its parent class.
Brian

Rob Said:
Is this an ObservableCollection?

Are you raising the PropertyChanged event for each property on the class that implement the INotifyPropertyChanged interface?

If you are doing these, then it should be simple enough to wire up events in your property handlers for each row in the collection.

Not 100% sure of your layout but you should be able to bind to those specific UI properties that would change when values change in the collection.  You are not restricted to just binding to data display values.  You might want to create some IValueConverters that look at your internal data and then return values applicable to a UI setting such as enabled/disabled or visible/hidden type of stuff.

Brian Risley replied to Brian Risley on 18-Mar-11 03:52 PM
Ok,
I have events worked out and can deal with a collection notifying the parent when a record has changed.

What I am looking for now is this:
I have a class that controls my itemlist objects.  In a customer class, I may have a customertype property and a customertypedesc property.  (A view would be used to link the type to a table with the desc when it is initially loaded)
Now I want to edit this customer class, so I have an ILI class as a property and populate it.  This is tied to a combobox in XAML.  When the user selects a value, the ILI sees this and sets a currentval and currenttext property based on the value selected and data loaded from the desc table in the observable collection.
I have all of this working fine.
What I am looking at is there a way to pass a property from the parent for the customertype/customertypedesc into properties in the itemlist control class so that I could set these values when the itemlist control processes the selection event?  I know I could trigger an event back to the customer class and have it do it there, but I am looking to see if there is something I can do where I only have to put the pointers to the customer properties into the itemlist class when I am setting it up and loading the collection.
(I do plan on triggering an event back to the customer to indicate that an itemlist property has been changed, but I would like to avoid having to determine which property was changed.)