1 回答

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果您希望組合框更改列表框中所選項(xiàng)目的值,您可以像這樣綁定 SelectedItem。
<ComboBox ItemsSource="{Binding ComboList}" SelectedItem="{Binding ElementName=listBox, Path=SelectedItem.ChosenValue}" />
否則,如果您確實(shí)想在組合框更改時(shí)更改列表中所有項(xiàng)目的屬性,則需要在屬性設(shè)置器中的代碼后面執(zhí)行此操作。
<ComboBox ItemsSource="{Binding ComboList}" SelectedItem="{Binding SelectedValue}"/>
在視圖模型中
private string _SelectedValue;
public string SelectedValue
{
get => _SelectedValue;
set
{
_SelectedValue = value;
foreach (var item in MyObColl.ToList()) item.ChosenValue = _SelectedValue;
}
}
- 1 回答
- 0 關(guān)注
- 163 瀏覽
添加回答
舉報(bào)