I modified tabDynamic_PreviewDrop
method, it can add TabItem by dragging Item to _tabAdd
.
private void tabDynamic_PreviewDrop(object sender, DragEventArgs e)
{
tabDynamic.DataContext = null;
string[] fileloadup = (string[])e.Data.GetData(DataFormats.FileDrop);
int count = _tabItems.Count;
TabItem tab = new TabItem();
tab.Header = string.Format("Tab {0}", count);
tab.Name = string.Format("tab{0}", count);
tab.HeaderTemplate = tabDynamic.FindResource("TabHeader") as DataTemplate;
tab.MouseDoubleClick += new MouseButtonEventHandler(tab_MouseDoubleClick);
tab.Content = File.ReadAllText(fileloadup[0]);
_tabItems.Insert(count - 1, tab);
tabDynamic.DataContext = _tabItems;
tabDynamic.SelectedItem = tab;
e.Handled = true;
}
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread.
[5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html