我正在尝试将多选列表框绑定到list<int>
我拥有的(IdProv)。我所做的是将 SelectedValue 绑定到一个属性,该属性将该值添加或删除到list<int>
. 和 listbox.SelectedItems都list<int>
应该同步。
列表框的 xaml 代码如下所示:
<ListBox DisplayMemberPath="Name"
SelectedValuePath="Id"
SelectedValue="{Binding Path=IdProv,
Mode=OneWayToSource,
ValidatesOnExceptions=True}"
SelectionMode="Multiple" />
ItemsSource 在代码隐藏中设置。它是具有 Id 和 Name 属性的产品列表
问题在于未正确更新的 SelectedValue 属性(SelectedItem 都没有)。它们仅在选择第一个项目时设置,但随后它们会更新。
also when selecting an item making a click on the list, the SelectedValue just updates when I click the item that was first added.
知道发生了什么吗?我确定我在绑定中犯了一个愚蠢的错误,但这花了我几个小时,我无法弄清楚!
谢谢,马丁