gpt4 book ai didi

WPF 组合框绑定(bind)

转载 作者:行者123 更新时间:2023-12-04 06:12:20 25 4
gpt4 key购买 nike

我有两个组合框,它们都与同一个源绑定(bind)。

<ComboBox ItemsSource="{Binding Source={StaticResource UsersViewSource}}"

当我在第一个中更改某些内容时,它也会反射(reflect)到第二个中。而且我不知道如何使用相同的 ItemsSource 单独保留它们的 SelectedItem 值。

最佳答案

IsSynchronizedWithCurrentItem属性应设置为 False:

true if the SelectedItem is always synchronized with the current item in the ItemCollection; false if the SelectedItem is never synchronized with the current item; null if the SelectedItem is synchronized with the current item only if the Selector uses a CollectionView. The default value is 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>

关于WPF 组合框绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2458420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com