XPath databinding across views & regions

Aug 28, 2009 at 5:33 PM

When databinding within a module what is the best practice for event routing?  I have been working with the pure XAML code here http://blogs.msdn.com/tolong/archive/2006/12/20/bind-controls-to-rss-feed-using-wpf.aspx.  In that XAML we have a xmldataprovider and we are calling an rss <link> through XPath query by wrapping a stackpanel, dockpanel, listbox, and frame in the same binding.  Works great in pur XAML if everything is in the same window, control, or view.

I broke the frame out into a seperate region from the listbox control to leverage the composite application approach.  When a new feed is selected in the listbox I would like the selectionchanged event (or some property changing event - or any event) to notify the frame that its XPath=link source has changed.  Since I am working within a module I would prefer this to be in pure XAML, but it seems like I need to do some code behind and event routing.  Since the event and source change occurs within a view should I use INotifypropertychange - or should I somehow leverage the IEventAggregator since I am working within a composite application and attempting to use the CAL practice guidance?

Conceptually it seems like I could tackle the problem either way.  However, my approaches to date have failed in part because I cannot find a method type that updates the frame source XPath through databinding.  I would like to avoid parsing the XPath link and then passing a string (XPath to string would be the method I assume).  This seems to defeat the whole purpose of inheretance, and the fact that the XPath is supposed to grab the link through binding with no-muss-no-fuss.  Any suggestions would be greatly appreciated.  Examples would be even more so.

Aug 31, 2009 at 6:35 PM


If I understand your scenario correctly you have two different views in the same module. One of them has a listbox (lets call it ListBoxView)and the other one shows some information in a frame, changing a source based on the selected item in the ListBoxView (lets call this FrameView). You can use the MVVM pattern which will allow you to maximize the usage of databinding and reduce the view's code behind. One possible way to achieve this interaction would be like this:

  1. Have a property in the ViewModel of the ListboxView that relates to the currently selected item.
  2. Publish an event, which as you said can be NotifyPropertyChanged, which can be handled by a component in the module that is in charge of orchestrating the entire module's interaction. It can be something like a controller.
  3. The controller handles the event by updating in the FrameViewModel's "Source" property. This propery is binded in XAML to the Frame's source property.

A couple of months ago we created a demo application that leverages a similar scenario. Not all functionality is implemented as I explained above, but it can be a good starting point.

Please let me know if this helps.

Damian Schenkelman