WP7 Problem Binding to UserControl Dependency Property

Oct 18, 2010 at 9:57 PM

I'm having a problem binding to a user control dependency property.

My XAML looks like this:

 		DataContext="{Binding HousePrices}"
                SelectedItem="{Binding SelectedPriceFrom, Mode=TwoWay}" >

SelectedItem is a dependency property. I can see it getting set but SelectedPriceFrom never gets set.

I think the problem is that because DataContext binds to HousePrice, the SelectedItem binding is looking for a property relative to HousePrice and failing.

The user control appears 4 times on my phone page, each time with a different data context and selected item binding. 

From reading and re-reading the docs I'm guessing that conductors could help but I can't figure out how.

Any ideas?



Oct 19, 2010 at 1:32 AM

I'm not sure to understand your actual scenario, but let's try a lucky guess.

  ItemsSource="{Binding HousePrices.AllPrices}"
  SelectedItem="{Binding HousePrices.SelectedPriceFrom, Mode=TwoWay}" >

Note that I added an ItemsSource dependency property that you have to bind to the corresponding ItemSource of the list control *inside* UserControls:HorizontalListBox.
I called AllPrices the property which contains all available prices (I don't know the actual name). 

Can this fix the issue? If not, I'm afraid you have to give some other details about the shape of your VM and the content of UserControls:HorizontalListBox.



Oct 19, 2010 at 2:51 AM

I had tried this before but your response prompted me to give it another go. I had missed out adding DP property changed event handlers to update the user control properties but put them in this time and all worked.



Oct 19, 2010 at 8:59 AM

Murphy must have been sleeping :-)