public static DependencyObject GetTopLevelControl(DependencyObject control) { System.Diagnostics.Debug.WriteLine("Searching for top level control"); DependencyObject tmp = control; DependencyObject parent = null; while ((tmp = VisualTreeHelper.GetParent(tmp)) != null) { System.Diagnostics.Debug.WriteLine("Item: " +tmp.ToString()); parent = tmp; } return parent; }Normally the output from the above is:
Searching for top level control Item: System.Windows.Controls.Primitives.ToolBarPanel Item: System.Windows.Controls.DockPanel Item: System.Windows.Controls.Border Item: System.Windows.Controls.Grid Item: System.Windows.Controls.ToolBar Header: Items.Count:4 Item: System.Windows.Controls.ToolBarTray Item: System.Windows.Controls.DockPanel Item: System.Windows.Controls.ContentPresenter Item: System.Windows.Controls.Border Item: WpfApplication1.Pages.AdminDesign Item: System.Windows.Controls.ContentPresenter Item: System.Windows.Documents.AdornerDecorator Item: System.Windows.Controls.Grid Item: System.Windows.Controls.DockPanel Item: System.Windows.Controls.Border Item: System.Windows.Navigation.NavigationWindowHowever when the Toolbar overflow panel is visible I get this:
Searching for top level control Item: System.Windows.Controls.Primitives.ToolBarPanel Item: System.Windows.Controls.DockPanel Item: System.Windows.Controls.Border Item: System.Windows.Controls.Grid Item: System.Windows.Controls.ToolBar Header: Items.Count:2 Item: System.Windows.Controls.ToolBarTray Item: System.Windows.Controls.ContentPresenter Item: System.Windows.Controls.Border Item: LLControls.UserControls.ConnectionOwner Item: System.Windows.Controls.Primitives.ToolBarOverflowPanel Item: System.Windows.Controls.Border Item: Microsoft.Windows.Themes.SystemDropShadowChrome Item: System.Windows.Documents.NonLogicalAdornerDecorator Item: System.Windows.Controls.Decorator Item: System.Windows.Controls.Primitives.PopupRoot(which isn't much use) This happens whether the ComboBox itself is in the overflow panel or not. Can't find any documentation for this behaviour - anyone explain?