/// <summary> /// Gets the Orientation which will be used for the drag drop action. /// Normally it will be look up to find the correct orientaion of the inner ItemsPanel, /// but sometimes it's necessary to force the oreintation, if the look up is wrong. /// If so, the ItemsPanelOrientation value is taken. /// </summary> /// <param name="itemsControl">The ItemsControl for the look up.</param> /// <returns>Orientation for the given ItemsControl.</returns> public static Orientation GetItemsPanelOrientation(this ItemsControl itemsControl) { var itemsPanelOrientation = DragDrop.GetItemsPanelOrientation(itemsControl); if (itemsPanelOrientation.HasValue) { return(itemsPanelOrientation.Value); } if (itemsControl is TabControl) { //HitTestUtilities.HitTest4Type<TabPanel>(sender, elementPosition) //var tabPanel = itemsControl.GetVisualDescendent<TabPanel>(); var tabControl = (TabControl)itemsControl; return(tabControl.TabStripPlacement == Dock.Left || tabControl.TabStripPlacement == Dock.Right ? Orientation.Vertical : Orientation.Horizontal); } var itemsPresenter = itemsControl.GetVisualDescendent <ItemsPresenter>() ?? itemsControl.GetVisualDescendent <ScrollContentPresenter>() as UIElement; if (itemsPresenter != null && VisualTreeHelper.GetChildrenCount(itemsPresenter) > 0) { var itemsPanel = VisualTreeHelper.GetChild(itemsPresenter, 0); var orientationProperty = itemsPanel.GetType().GetProperty("Orientation", typeof(Orientation)); if (orientationProperty != null) { return((Orientation)orientationProperty.GetValue(itemsPanel, null)); } } // Make a guess! return(Orientation.Vertical); }