WPF 控件,当绑定 属性 到 `ItemsSource` 更改时禁用对 `SelectedItem` 的更改

WPF controls, disable changes to `SelectedItem` when bound property to `ItemsSource` changes

当我使用 ComboBox 或其他具有 ItemsSourceSelectedItem 属性 绑定的控件时,每次在 运行 期间的初始绑定和每次绑定到 ItemsSource 的集合发生变化时,我都会体验到绑定 SelectedItem 对象的内容发生了变化。

如何禁用它?

例如:

我有<ComboBox MinWidth="300" ItemsSource="{Binding AvailableMasters}" SelectedItem="{Binding SelectedMaster}">

当我 运行 应用程序 SelectedMaster 属性 被分配到 AvailableMasters 中的第一项。此外,每次 AvailableMasters 集合更改(例如,通过将新集合分配给 属性),SelectedMaster 都会再次调整。

期望的行为是 SelectedItem (SelectedMaster) 只有 populated/changed 当最终用户用鼠标点击该项目/从 ComboBox 或其他控件。

在更新集合并在 SelectedMaster 属性 中使用它之前设置一个 flag/bool 属性。还是您只需要 XAML 个解决方案?