Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VisualTree variation in Toolbar
Message
De
21/07/2009 10:33:20
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Titre:
VisualTree variation in Toolbar
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01413550
Message ID:
01413550
Vues:
109
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 ?
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform