我有一个 ListBox,其显式绑定设置为 SelectedValue。
SelectedValue="{Binding Path=Property, UpdateSourceTrigger=Explicit}"
ListBox 的 ItemSource 是一个 ObservableCollection。
当我选择 ListBox 的一项并按“Enter”时,我以这种方式更新属性值:
BindingExpression be = listBox.GetBindingExpression(ListBox.SelectedValueProperty);
be.UpdateSource();
现在,我遇到了这个问题:我必须通过窗口上的特定操作来重置 ListBox 的 ItemsSource,并且当为 ItemsSource 调用“Clear”方法时,与 SelectedValue 的绑定被更新(为空)!为什么?
怎么能避免呢?