C# WPF选项卡控件-在ItemsSource CollectionChanged事件期间更改SelectedItem
我在WPF选项卡控件中遇到了一些奇怪的行为。对于其他基于选择器的类,如ComboBox,我无法复制它 当我将TabControl绑定到ItemsSource并向其中添加一个项,以便触发CollectionChanged事件时,我会尝试更改事件处理程序中的SelectedItem属性。不幸的是,用户界面没有自我更新。内容更改,但未选择标题 我的XAML:C# WPF选项卡控件-在ItemsSource CollectionChanged事件期间更改SelectedItem,c#,wpf,C#,Wpf,我在WPF选项卡控件中遇到了一些奇怪的行为。对于其他基于选择器的类,如ComboBox,我无法复制它 当我将TabControl绑定到ItemsSource并向其中添加一个项,以便触发CollectionChanged事件时,我会尝试更改事件处理程序中的SelectedItem属性。不幸的是,用户界面没有自我更新。内容更改,但未选择标题 我的XAML: <TabControl ItemsSource="{Binding Path=ints}" SelectedIt
<TabControl ItemsSource="{Binding Path=ints}"
SelectedItem="{Binding Path=SelectedInt}"/>
同时,异步更改SelectedItem属性会导致UI正确更新自身:
this.ints.CollectionChanged += (sender, args) => Application.Current.Dispatcher.BeginInvoke(new Action(() => this.SelectedInt = this.ints.First()));
在CollectionChanged事件期间调用SelectedItem属性的PropertyChanged事件时,它似乎没有正确传播。它可能以某种方式被吸收
对此行为的确切解释是什么?您是否尝试将SelectedItem的绑定模式设置为双向
?
this.ints.Add(2);
this.SelectedInt = this.ints.First();
this.ints.CollectionChanged += (sender, args) => Application.Current.Dispatcher.BeginInvoke(new Action(() => this.SelectedInt = this.ints.First()));