iLe*_*ing 8 wpf binding combobox
我有两个Comboboxes,它们都绑定了相同的Source.
<ComboBox ItemsSource="{Binding Source={StaticResource UsersViewSource}}"
Run Code Online (Sandbox Code Playgroud)
当我在第一个中改变某些东西时,它也反映在第二个中.我不知道如何使用相同的ItemsSource分别保留他们的SelectedItem值.
Met*_*urf 10
该IsSynchronizedWithCurrentItem属性应设置为False:
如果SelectedItem始终与ItemCollection中的当前项同步,则返回true;否则返回true.如果SelectedItem从未与当前项同步,则返回false;否则返回false.如果SelectedItem仅在Selector使用CollectionView时与当前项同步,则返回null.默认值为null.
这是一个示例:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<x:Array x:Key="myStrings" Type="sys:String">
<sys:String>one</sys:String>
<sys:String>two</sys:String>
<sys:String>three</sys:String>
<sys:String>four</sys:String>
<sys:String>five</sys:String>
</x:Array>
</Page.Resources>
<StackPanel Width="200">
<ComboBox IsSynchronizedWithCurrentItem="False" Margin="25"
ItemsSource="{Binding Source={StaticResource myStrings}}" />
<ComboBox IsSynchronizedWithCurrentItem="False" Margin="25"
ItemsSource="{Binding Source={StaticResource myStrings}}" />
</StackPanel>
</Page>
Run Code Online (Sandbox Code Playgroud)