Saturday, March 24, 2012

ListView, dataContext, and Actions

I'm working with the (client-side) Atlas ListView control, and seeing some behavior I didn't expect. The code is binding the ListView to an XmlDataSource, with item templates that use XPathBindings to populate hyperlinks, labels, etc. The basic stuff works - for example, there's an anchor in the markup with a corresponding Hyperlink component in the XML Script, and using the XpathBinding to populate the Hyperlink text works great.

However, the other thing I'm trying to do is to wire up the click event to a SetPropertyAction, and set properties on the SetPropertyAction using XPathBinding to the same listview data item that the Hyperlink is bound to. That doesn't seem to be working. My general impression is that the dataContext for a component is supposed to be inherited from its parent if it isn't set explicitly on that component. I assumed that would carry over to the action, so the context for bindings on the action would be the ListView item. That doesn't seem to be the case.

Looking at the Atlas code, it seems that an Action always returns itself as its data context. Is there a reason for that? Is there some other way of accomplishing what I'm trying to do?

Kevin

OK, I found a blog post that explains why the dataContext on the Action is set to the action itself, and how to address that. Unfortunately, I'm now running in the problem that I reported before about bindings on Actions. Since Actions always evaluate both the In and Out directions of bindings, they are incompatible with XPathBindings (which throw an error in the evaluateOut call). I think there's a bit of a design problem in this part of Atlas.

No comments:

Post a Comment