Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind to CurrentItem of ICollectionView

I want to a property to the current item of a ICollectionView how can I do it? The ICollectionView is used for binding to a combo box, how can I bind another control to the ICollectionView's selected item?

like image 842
Jiew Meng Avatar asked Nov 02 '10 13:11

Jiew Meng


3 Answers

Check out this cheat sheet. In particular, check out the / binding symbol, which references the current item in a collection view.

like image 176
Dan Bryant Avatar answered Sep 30 '22 16:09

Dan Bryant


Setting IsSynchronizedWithCurrentItem on the ComboBox will update the current item with its selection (not sure if you're already doing this). You can then bind the same collection and access its current item with the binding:

<ComboBox ItemsSource="{Binding Names}" IsSynchronizedWithCurrentItem="True" />
<Button Content="{Binding Path=Names/}"/>
like image 36
John Bowen Avatar answered Sep 30 '22 16:09

John Bowen


Give your ComboBox a name and bind to it's SelectedItem.

For example:

<ComboBox x:Name="MyComboBox" ItemsSource="{Binding MyList}" />

<Grid DataContext={Binding ElementName=MyComboBox, Path=SelectedItem>
...
</Grid>
like image 32
Rachel Avatar answered Sep 30 '22 15:09

Rachel