Different views in WPF/Silverlight

In my early WPF days I noticed the magic that having two different controls bound to the Same ObservableCollection meant that when I selected an item in one control, the same item got selected in the other.... which i I didn't want.

CollectionViewSource To the rescue

<Window.Resources>
<local:MyData x:Key="MyData"/>  
    <CollectionViewSource x:Key="AllData" Source="{StaticResource MyData}"/>  
    <CollectionViewSource x:Key="SearchData" Source="{StaticResource MyData}" Filter="MySearch"/>  
</Window.Resources> 
 
<ListBox ItemsSource="{Binding Source={StaticResource AllData}}"/>  
<ListBox ItemsSource="{Binding Source={StaticResource SearchData}}"/>

 

 

Comments are closed