ButchersBoy / Dragablz

Dragable and tearable tab control for WPF
http://dragablz.net
MIT License
2.17k stars 321 forks source link

Update header from code behind, when tab is dragged out #195

Closed BornToBeRoot closed 6 years ago

BornToBeRoot commented 6 years ago

Hi,

i try to update the header text from the code behind. I have an action, which is passed into the tab content.

In the tab control host:

public ObservableCollection<DragablzPingTabItem> TabItems { get; private set; }
Action<Tuple<int, string>> ChangeTabTitleAction;
private void ChangeTabTitle(Tuple<int, string> obj)
{
    TabItems.First(x => x.ID == obj.Item1).Header = obj.Item2;
}

In the control:

ChangeTabTitle.BeginInvoke(Tuple.Create(_tabId, Host), null, null);

But this only works, when the tab is not dragged out of the main window.

Any idea how to fix this?

Repo: https://github.com/BornToBeRoot/NETworkManager Ping

BornToBeRoot commented 6 years ago

This may not be nice, but at least it works...

Window window = Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.IsActive);

if (window != null)
{
    foreach (TabablzControl tabablzControl in VisualTreeHelper.FindVisualChildren<TabablzControl>(window))
    {
        tabablzControl.Items.OfType<DragablzPingTabItem>().First(x => x.ID == _tabId).Header = Host;
    }
}