I can add and remove tabs similar to a famous MSDN article . Mostly a ObservableCollection<TabViewModels>. And I add tabs like _tabs.Add(new TabViewModel()), but the newest tab is not focused. I want to focus on him. How to do it?
1 way to do it
since I have a view source for my observable collection, I can do the following ... another option would be @vorrtex
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);
}
if (e.OldItems != null && e.OldItems.Count > 0)
foreach (TabViewModel tab in e.OldItems)
tab.CloseRequested -= OnCloseRequested;
}
source
share