MVVM Modules?

Topics: Prism v4 - WPF 4
Feb 7, 2013 at 6:54 PM
Hi All,

I'm still learning wpf - so its very possible I have been searching for the wrong terms, hence I've not found what I'm looking for!

I've written a small app - a host with a list down the left hand side - just populated with "item 1", "item 2", "item3", etc and a corresponding number, 1, 2, 3 etc...

and a region (I've got this working without prism, just using MEF, which loads a usercontrol into a contentprovider) my problem started with the inability to bind my usercontrol (view) with the viewmodel. I can correctly pass the number of the item selected into the module, but the textblock bound to the property does not update at all. I am calling the RaisePropertyChanged event, which I can see when debugging but still the view does not update.

So this lead me to prism - but I'm having the same problem - I can't seem to find a good [simple] example not written in Silverlight. is it possible to write a module fully using the MVVM model and load it into a host app correctly?


Feb 8, 2013 at 12:51 PM
Hi Scott,

It's possible to implement a implement a module fully using the MVVM pattern, this can be seen in many of the Quickstarts or even in the StockTrader Reference Implementation which are provided with Prism.

Also, for a simple sample to start with, I believe you could check David Hill's Prism Template Pack for Visual Studio 2010 (e.g. the QuickStart Solution MEF)

In my opinion if your modules are correctly loading then I believe that your problem could be related to the wiring of the view model, in which case for more information about this you could check the following section of the documentation:
On the other hand, I recommend you to check the In the Box – MVVM Training which portrays an interactive guidance on the use of the MVVM pattern, an examples using the IOC pattern in WPF applications:
I hope you find this handy,

Agustin Adami
Feb 9, 2013 at 7:10 AM
Hi Agustin,

thanks very much for the links, i did fi ally get it so that when i passed the viewmoldel object it correctly shows my view, by registering the resource dictionary with an export and in the main app registering it with the main app. Resource dictionary.

my next problem i think is related to mef, because now my properties will not update. So in my iplugin interface i defined a setItem(int itemnumber), i can call this in my plugin from the host app when changing the listbox. I see the property being set, i see the raisepropertychanged fire, but the textblock bound to it does not change. Im not quite sure how to bibble that event up to the host which is what i recon needs to happen?

also, im sorry about the grammar / spelling of thus post, writing on a wp8 device.

Feb 13, 2013 at 8:00 PM
Hi Scott,

So far, based on the information you provided I couldn't find the cause of this behavior. In order to help you further with this it would be helpful if you could provide us with more specific information on how you are implementing this, for example the xaml of the view or how / where you are defining the bindings.

Also, one thing to consider is that this problem could be caused if you are defining your bindings inside a DataTemplate, as this will be set to the data object itself and not the DataContext of the parent view. If this is the case, there are different approaches that can be followed in order to point to the right Datacontext source, for example a common approach is to use RelativeSource property with the FindAncestor value to point the type of the parent control that has its Datacontext set to the corresponding view model, for example:
<TextBlock Text=“{Binding DataContext.MyProperty, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}“></TextBlock>

Agustin Adami