C # / WPF: why the tab is not focusing properly

I have a tab control

<TabControl Height="Auto" Grid.Row="1" ItemsSource="{Binding Tabs}" IsSynchronizedWithCurrentItem="True">

This is due to Tabsc ViewModel. I also used CollectionViewSourceto focus tabs

protected ObservableCollection<TabViewModel> _tabs;
protected ICollectionView _tabsViewSource;

public ObservableCollection<TabViewModel> Tabs
{
    get { return _tabs; }
}
public void OnTabsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    if (e.NewItems != null && e.NewItems.Count > 0)
        foreach (TabViewModel tab in e.NewItems)
        {
            tab.CloseRequested += OnCloseRequested;
            _tabsViewSource.MoveCurrentTo(tab); // focus newly created tab
        }
    if (e.OldItems != null && e.OldItems.Count > 0)
        foreach (TabViewModel tab in e.OldItems)
            tab.CloseRequested -= OnCloseRequested;
}

When I have more than one tab, when I create new tabs, the tabs are focused correctly

alt text

when there are no tabs, the new tabs do not seem to focus properly. pay attention to the tab title

alt text

how can i fix this? or what causes this behavior? a text box is displayed (tab contents), but the title does not appear as its selected

UPDATE

It works with a fresh file / project ... hmm ... there must be some kind of related code ... I could redo this part ...

+3
2

IsSynchronizedWithCurrentItem="True" , TabControl.ItemsSource ICollectionView.

, ObservableCollection ICollectionView , tabboard.

public TabViewModel CurrentTabViewModel
{
    get
    {
        return _tabs.CurrentItem as TabViewModel:
    }
    set
    {
        _tabs.MoveCurrentTo(value);
    }
}

TabControl SelectedItem CurrentTabViewModel

<TabControl SelectedItem="{Binding Path=CurrentTabViewModel}" ... />
+1

, , . SelectedIndex tabView = 0 → .

<TabControl Height="Auto" 
  Grid.Row="1" 
  ItemsSource="{Binding Tabs}" 
  IsSynchronizedWithCurrentItem="True" 
  SelectedIndex="0">
0

Source: https://habr.com/ru/post/1770654/