Databinding between UserControls?

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-03-19T20:38:49Z Indexed on 2010/03/19 20:41 UTC
Read the original article Hit count: 689

Filed under:
|
|
|

I've got a situation where one of my UserControls would like to display a list of strings in a droplist, and the ItemsSource is set to another UserControl's ObservableCollection.

The consumer of this data has its droplist defined in XAML like this:

<ComboBox Grid.Column="1" SelectedItem="{Binding MyItem, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.MyItems}" Margin="3"></ComboBox>

MyItems is defined as an ObservableCollection<string> in the producer UserControl.

Now everything works fine when the controls are loaded. As long as MyItems is populated first, and then the consumer UserControl is displayed, all of the items are there. I obviously don't get any errors in the Output Window or anything like that.

The issue I have is that when the ObservableCollection is modified, those changes are not reflected in the consumer UserControl! I've never had this problem before, but all of my previous uses of ObservableCollection with updating the collection are within a single control, and databinding is not inter-UserControl.

Is there something I did wrong? Is there a good way to actually debug this? Reed Copsey indicates here that inter-UserControl databinding is possible. Unfortunately, my favorite Bea Stollnitz article on WPF databinding debugging doesn't suggest anything that I could use for this particular problem.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding