Happy stress free coding

Oct 9, 2008

Master detail and currency handling in wpf

In wpf there is no CurrencyManager for each binding context like in windows forms. Instead everything you bind is wrapped in a CollectionView and the CollectionView keeps the notion of currency; which item that is currently the current item.

Fine. No problem. BUT in order for your gui controls to actually honor the CollectionView's notion of currency you MUST explicitly tell it to. How? Set IsSynchronizedWithCurrentItem="True"

Like this:

 
 

<ListBox Name="lb21" ItemsSource="{Binding}" ItemTemplate="{StaticResource dataTemplateClass2}" IsSynchronizedWithCurrentItem="True"></ListBox>

 

<ListBox Name="lb22" ItemsSource="{Binding}" ItemTemplate="{StaticResource dataTemplateClass2}" IsSynchronizedWithCurrentItem="True"></ListBox>

 

<TextBlock Name="ThisTBFollowsTheOtherTB1" Text="{Binding ElementName=lb21,Path=SelectedValue.Attribute1}"></TextBlock>

 

<TextBlock Name="ThisTBFollowsTheOtherTB2" Text="{Binding ElementName=lb22,Path=SelectedValue.Attribute1}"></TextBlock>

 

Ok. The other thing that drove me mad was how to, via the Path expression, navigate over a list, getting the current item…

<TextBlock Name="tb22" Text="{Binding Source={StaticResource referenceHandle1},Path=List/Attribute1}"></TextBlock>
…and the trick is the "/" between the collection (List in the example) and the property of the current object (Attribute1 in the sample)

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home