Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VisualTree variation in Toolbar
Message
From
21/07/2009 13:24:55
John Baird
Coatesville, Pennsylvania, United States
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01413550
Message ID:
01413602
Views:
39
>Hi,
>Found some odd behaviour that I wasn't expecting. I have a Combobox in a Toolbar which calls code to locate the top level container in which it is sited. Here's the helper method (which is called with a reference to the ComboBox):
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.NavigationWindow
>However 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?
>(It's not actually a problem since I can use the LogicalTreeHelper instead which is consistent (and more efficient :-})
>
>P.S Quiet here lately ?


I'm taking a guess here, but non visible components don't take up any space in the tree and are not visible to any VisualTreeHelper methods. We had a tab control with 3 pages and 3 grids .... only the visible tab and grid could be seen by walking the visual tree.

Hope this helps....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform