gpt4 book ai didi

c# - ComboBox SelectedItem 绑定(bind)不更新

转载 作者:行者123 更新时间:2023-11-30 19:12:42 24 4
gpt4 key购买 nike

我有点疑惑:这有效:

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Label Content="Rol" />
<ComboBox ItemTemplate="{StaticResource listRollen}"
Height="23" Width="150"
SelectedItem="{Binding Path=SelectedRol, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
ItemsSource="{Binding Path=allRollen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>

SelectedRol 的属性是:

public TblRollen SelectedRol
{
get { return _selectedRol; }
set
{
if (_selectedRol != value)
{
_selectedRol = value;
OnPropertyChanged("SelectedRol");
}
}
}

但这行不通:

<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Label Content="Soort" />
<ComboBox ItemTemplate="{StaticResource listSoorten}"
Height="23" Width="150"
ItemsSource="{Binding Path=allSoorten}"
SelectedItem="{Binding Path=SelectedProduct, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>

具有以下属性的 SelectedProduct:

public TblProduktSoorten SelectedProduct
{
get { return _selectedPSoort; }
set
{
if (_selectedPSoort != value)
{
_selectedPSoort = value;
OnPropertyChanged("SelectedProduct");
}
}
}

我在代码中的某处设置了 SelectedProduct = p.TblProduktSoorten,在调试时,我看到属性设置正确...

最佳答案

DataGrid 中的组合框?

如果组合框在 DataGrid 中,您必须添加:

Mode=TwoWay, UpdateSourceTrigger=PropertyChanged

看这个:https://stackoverflow.com/a/5669426/16940

关于c# - ComboBox SelectedItem 绑定(bind)不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6226385/

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