|
Hi Josh,
Have you tried to use FindVisualTreeRoot function to test on the multiple-layer of MenuItems.
It seems that for Sub-MenuItems, it needs to trace up through the VisualTreeHelper first.
When it reaches to the root (Popup Root), need to use VisualTreeHelper to jump out and get the real Parent MenuItem for it.
Currently, for FindVisualTreeRoot function, when it reaches Popup Root (which still is Visual), it will use VisualTreeHelper to get parent and get a null return.
My question is how to handle this situation so that we can get the real root through both VisualTreeHelper and VisualTreeHelper?
modified 28-May-22 6:51am.
|
|
|
|
|
Any WPF developer shall read that one !
|
|
|
|
|
Thank you, it has been very helpful for me.
Regards, Steffen
|
|
|
|
|
Good... Gives a good introduction to visual and logical tree
|
|
|
|
|
hi any buddy can tell me example of reflection,When and how we get property of checkbox control by passing only class name in string form.
|
|
|
|
|
Thanks!It's useful to me.
|
|
|
|
|
Hello,
converting in Visual Studio 2010 gives errors:
<pre lang="asm">Error 1 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\LogicalTreeDumper.cs 2 14 ElementTreeComparison
Error 2 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Utils.cs 2 14 ElementTreeComparison
Error 3 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 2 14 ElementTreeComparison
Error 4 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Program.cs 2 14 ElementTreeComparison
Error 5 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\LogicalTreeDumper.cs 3 14 ElementTreeComparison
Error 6 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 3 14 ElementTreeComparison
Error 7 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Program.cs 3 14 ElementTreeComparison
Error 8 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 4 14 ElementTreeComparison
Error 9 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Program.cs 4 14 ElementTreeComparison
Error 10 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Program.cs 5 14 ElementTreeComparison
Error 11 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Program.cs 6 14 ElementTreeComparison
Error 12 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\LogicalTreeDumper.cs 9 33 ElementTreeComparison
Error 13 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 10 33 ElementTreeComparison
Error 14 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Utils.cs 27 23 ElementTreeComparison
Error 15 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Utils.cs 27 59 ElementTreeComparison
Error 16 The type or namespace name 'MouseButtonEventArgs' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Program.cs 28 69 ElementTreeComparison
Error 17 The type or namespace name 'MouseButtonEventArgs' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Program.cs 37 70 ElementTreeComparison
Error 18 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\LogicalTreeDumper.cs 38 16 ElementTreeComparison
Error 19 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\LogicalTreeDumper.cs 38 60 ElementTreeComparison
Error 20 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 40 16 ElementTreeComparison
Error 21 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 40 59 ElementTreeComparison
Error 22 The type or namespace name 'RoutedEventArgs' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\Program.cs 46 48 ElementTreeComparison
Error 23 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\LogicalTreeDumper.cs 62 16 ElementTreeComparison
Error 24 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\LogicalTreeDumper.cs 62 53 ElementTreeComparison
Error 25 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 67 16 ElementTreeComparison
Error 26 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 67 52 ElementTreeComparison
Error 27 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 90 28 ElementTreeComparison
Error 28 The type or namespace name 'DependencyObject' could not be found (are you missing a using directive or an assembly reference?) H:\Projekty\ElementTreeComparison\ElementTreeComparison\VisualTreeDumper.cs 90 54 ElementTreeComparison
Warning 29 The primary reference "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86" or retarget your application to a framework version which contains "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86". ElementTreeComparison
Warning 30 The primary reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 31 The primary reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". ElementTreeComparison
Warning 32 The primary reference "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". ElementTreeComparison
Warning 33 The primary reference "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86" could not be resolved because it has an indirect dependency on the framework assembly "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86" or retarget your application to a framework version which contains "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 34 The primary reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 35 The primary reference "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". ElementTreeComparison
Warning 36 The primary reference "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86" could not be resolved because it has an indirect dependency on the framework assembly "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86" or retarget your application to a framework version which contains "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 37 The primary reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 38 The primary reference "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 39 The primary reference "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86" could not be resolved because it has an indirect dependency on the framework assembly "UIAutomationTypes, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86" or retarget your application to a framework version which contains "UIAutomationTypes, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 40 The primary reference "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "UIAutomationTypes, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "UIAutomationProvider, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "UIAutomationTypes, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 41 The primary reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "UIAutomationTypes, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "UIAutomationTypes, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 42 The primary reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Printing, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Printing, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 43 The primary reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "ReachFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" or retarget your application to a framework version which contains "ReachFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". ElementTreeComparison
Warning 44 The referenced component 'PresentationCore' could not be found.
Warning 45 The referenced component 'PresentationFramework' could not be found.
Warning 46 The referenced component 'UIAutomationProvider' could not be found.
Warning 47 The referenced component 'WindowsBase' could not be found.</pre>
Best regards!
|
|
|
|
|
johnyjj2,
put the project into the latest target framework and exchange the references to actual ones as you can lookup locations from your other projects references properties, e.g. PresentationCore.dll may be located in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\PresentationCore.dll
this will do it.
|
|
|
|
|
|
it took me a while to get my head around this but this is a pretty precise article.
|
|
|
|
|
|
My guess is, if you're building very dynamic user interface where you'd traverse Xaml structure (remember dhtml traversing DOM?) then you wouldn't really need to dig into the subject surrounding Visual/Logical tree... etc. But, if you do...
Xaml assumes tree structure comprising of "DependencyObject".
Some inherited from FrameworkElement (which inherits from Visual, which subclass from "DependencyObject")
Some other inherits from FrameworkContentElement (which inherits from ContentElement, again, it subclass from "DependencyObject").
And if iterating child nodes with LogicalTreeHelper, any type can be expected
Composition of the Logical Tree - FrameworkElement or FrameworkContentElement + Any other type (string/int/double... whatever)!
<br />
The logical tree is defined at the WPF framework-level, which means that the WPF base element that is most relevant for logical tree operations is either FrameworkElement or FrameworkContentElement. However, as you can see if you actually use the LogicalTreeHelper API, the logical tree sometimes contains nodes that are not either FrameworkElement or FrameworkContentElement. For instance, the logical tree reports the Text value of a TextBlock, which is a string<br />
Tree Traversal by LogicalTreeHelper: http://msdn.microsoft.com/en-us/library/system.windows.logicaltreehelper.aspx
The purpose/use of LogicalTree is for DependencyProperty inheritance/change notification, RoutedEvents, Resource resolution... etc
Composition of Visual Tree - FrameworkElement (which inherits from Visual) and Visual only!
Content elements (classes that derive from ContentElement) are not part of the visual tree; they do not inherit from Visual and do not have a visual representation.
<br />
Working with the logical tree is not nearly as clear-cut as the visual tree. For starters, the logical tree can contain objects of any type. This differs from the visual tree, which only contains instances of DependencyObject subclasses. When working with the logical tree, you must keep in mind a leaf node in the tree (a terminus) can be of any type.<br />
A similar concept to the logical tree is the visual tree. A visual tree is basically an expansion of a logical tree, in which nodes are broken down into their core visual components. Rather than leaving each element as a "black box," a visual tree exposes the visual implementation details. For example, although a ListBox is logically a single control, its default visual representation is composed of more primitive WPF elements: a Border, two ScrollBars, and more. Not all logical tree nodes appear in the visual tree; only the elements that derive from System.Windows.Media.Visual or System.Windows.Media.Visual3D are included. Other elements (and simple string content, as in Listing 3.1) are not included because they don't have inherent rendering behavior of their own. <br />
Tree traversal by VisualTreeHelper: http://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.aspx
The purpose of Visual Tree is control of visual rendering by WPF framework.
FrameworkElement class http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.aspx
(Inherit from http://msdn.microsoft.com/en-us/library/system.windows.media.visual.aspx)
FrameworkContentElement class http://msdn.microsoft.com/en-us/library/system.windows.frameworkcontentelement.aspx
(Inherit from http://msdn.microsoft.com/en-us/library/system.windows.contentelement.aspx)
REF:
http://www.codeproject.com/KB/WPF/WpfElementTrees.aspx
http://msdn.microsoft.com/en-us/library/ms753391.aspx
http://en.csharp-online.net/WPF_Concepts%E2%80%94Logical_and_Visual_Trees
Add a bit more code to Josh Smith's demo app (Utils.cs)
<br />
public static void DumpElement(object elem, bool isInitialElement, int indentLevel)<br />
{<br />
string indentation = new string(' ', indentLevel);<br />
string typeName = elem == null ? "(null)" : elem.GetType().Name;<br />
string text = String.Format("{0}{1}) {2}", indentation, indentLevel, typeName);<br />
if (isInitialElement)<br />
text += " [YOU CLICKED HERE]";<br />
#region Add more info ...<br />
if (elem is System.Windows.Media.Visual)<br />
{<br />
text += " Visual ";<br />
}<br />
if (elem is System.Windows.FrameworkElement)<br />
{<br />
text += " FrameworkElement ";<br />
}<br />
if (elem is System.Windows.FrameworkContentElement)<br />
{<br />
text += " FrameworkContentElement ";<br />
}<br />
#endregion<br />
Console.WriteLine(text);<br />
}<br />
REF: http://tinyurl.com/kqmrxro
dev
modified 15-Sep-14 21:22pm.
|
|
|
|
|
Very useful introduction to WPF trees.
|
|
|
|
|
Quote "Notice how the logical tree is very different now. It is much smaller than before; the root is a ButtonChrome instead of a Button; and the terminus is a ContentPresenter instead of a string. The reason for this change is that we are now looking at a logical island. This logical island is the logical tree of the template elements created to display the content of the Button"
My question is why logical root stops at "ClassicBorderDecorator" (is it the Window's border? Or I suspect it's the button's border) when ctrl-leftclick on the "Clear the console Window" (and if ctrl-leftclick on "Hold Ctrl and left-click to display logical tree" goes all the way up to the "Window" object)? Seems like breaks the chain. And I'm unsure how to tie in your discussion on "ContentPresentor" vs a being derived from "System.Windows.Controls.ContentControl" (see MSDN[^])
I notice TextBlock doesn't derive from ContentControl as in Button[^]
bit confused...
dev
|
|
|
|
|
Great article. The trees in WPF are far from straightforward.
|
|
|
|
|
Place below code in the demo window in the end before </stackpanel></window> and test by ctrl + right click on "Test Fails"
logical tree fails for popup route.
=============
<ToolBar>
<ToggleButton x:Name="tbtnTest" Content="Test"/>
<Popup StaysOpen="True"
PlacementTarget="{Binding ElementName=tbtnTest}"
IsOpen="{Binding ElementName=tbtnTest, Path=IsChecked}" >
<Border BorderBrush="Black" BorderThickness="1">
<StackPanel>
<ComboBox>
<ComboBoxItem>
<Label > TEST FAILS <Label>
</ComboBoxItem>
<ComboBox>
</StackPanel>
<Border>
<Popup>
<ToolBar>
|
|
|
|
|
Mike Hillberg, one of the WPF gurus at Microsoft, blogged about the visual tree and logical tree. His explanations are excellent. If you are interested in learning more about this topic, check out his post here[^].
:josh:
My WPF Blog[ ^]
All of life is just a big rambling blog post.
|
|
|
|
|
|
Josh,
This is a great article. It provides a great deal of useful information.
In the article you mentioned it is possible to jump to a different logical tree (or island) when walking down the tree for the case of templated controls. Could you provide some insight on how this might be accomplished? In my case, the templated control might not be visible yet because its on a tab that is not the active tab, hence the visual tree wouldn't contain the controls defined by the template.
Thanks,
Ken
|
|
|
|
|
Thanks Ken. If the visual tree does not exist, then I don't know how you could walk from a templated parent down to it's logical sub-tree. Traversing from logical island to logical island requires intermediary hops to the visual tree, so if the visual tree does not exist for a piece of UI, I'm not sure it's possible to hop to a logical island in that piece of UI. Granted, it's been a while since I last did this type of element tree programming, so I might be missing something here.
:josh:
My WPF Blog[ ^]
All of life is just a big rambling blog post.
|
|
|
|
|
Thanks for the reply. I fiqured this would be the case. I did come up with a work around. If I walk the logical tree and come across a ContentControl, I call that control's Template.LoadContent method, which loads the logical tree and returns the root node for the templated content, which I can then walk down. It seems to work fine, I'm just not sure how efficient it is. Thanks again!
|
|
|
|
|
ken_roberts@intuit.com wrote: If I walk the logical tree and come across a ContentControl, I call that control's Template.LoadContent method, which loads the logical tree and returns the root node for the templated content, which I can then walk down.
Nice! That's an interesting approach.
:josh:
My WPF Blog[ ^]
All of life is just a big rambling blog post.
|
|
|
|
|
Once again, a very nice article and a pleasurable reading
Adding it to my CP blog.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Thanks Paul.
:josh:
My WPF Blog[ ^]
Without a strive for perfection I would be terribly bored.
|
|
|
|
|
Another GOOD one!!!! Great job Josh!!!!
Regards
Marlon
|
|
|
|
|