我有点困惑:
这有效:
<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/