I can add & remove tabs similar to the famous MSDN article. Basically a ObservableCollection<TabViewModels>
. And I add tabs like _tabs.Add(new TabViewModel())
but the newest tab is not focused. I want to focus it. How do I do it?
1 way to do it
since i have a view source for my observable collection, I can do the below... another option will be @vorrtex method
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;
}