views:

3006

answers:

3

Is it possible to set the DataContext property of a usercontrol after the user control has been loaded, and force the usercontrol to rebind?

+2  A: 

I'm pretty sure that if you just set the datacontext again, it will rebind

Jacob Adams
+1  A: 

Setting the DataContext property should cause the rebind.

Anderson Imes
+2  A: 

If you need to do extra work when the DataContext changes you can use a custom DependencyProperty and bind it to the DataContext property. Use the DependencyPropertyChangedEventHandler to know when the DP changed.

For a more complete explanation see my blog post at http://msmvps.com/blogs/theproblemsolver/archive/2008/12/29/how-to-know-when-the-datacontext-changed-in-your-control.aspx.

Maurice