private void OnTabStripDrop(object sender, Windows.UI.Xaml.DragEventArgs e)
{
// This event is called when we're dragging between different TabViews
// It is responsible for handling the drop of the item into the second TabView
object obj;
object objOriginTabView;
if (e.DataView.Properties.TryGetValue(DataIdentifier, out obj) && e.DataView.Properties.TryGetValue(DataTabView, out objOriginTabView))
{
// TODO - BUG: obj should never be null, but occassionally is. Why?
if (obj == null || objOriginTabView == null)
{
return;
}
var originTabView = objOriginTabView as TabView;
var destinationTabView = sender as TabView;
var destinationItems = destinationTabView.TabItems;
var tabViewItem = obj as TabViewItem;
if (destinationItems != null)
{
// First we need to get the position in the List to drop to
var index = -1;
// Determine which items in the list our pointer is inbetween.
for (int i = 0; i < destinationTabView.TabItems.Count; i++)
{
var item = destinationTabView.ContainerFromIndex(i) as TabViewItem;
if (e.GetPosition(item).X - item.ActualWidth < 0)
{
index = i;
break;
}
}
// Remove item from the old TabView
originTabView.TabItems.Remove(tabViewItem);
if (index < 0)
{
// We didn't find a transition point, so we're at the end of the list
destinationItems.Add(tabViewItem);
}
else if (index < destinationTabView.TabItems.Count)
{
// Otherwise, insert at the provided index.
destinationItems.Insert(index, tabViewItem);
}
// Select the newly dragged tab
destinationTabView.SelectedItem = tabViewItem;
}
}
}