How can I get the type System.Windows.Controls.Primitive.PopupRoot?

Images can indicate a thousand words.

When I climb the visual tree, I see that the last parent is of type System.Windows.Controls.Pimitives.PopupRoot enter image description here

But Whey I'm trying to make a comparison with this type of VS, complains that it is not valid.

enter image description here

+6
source share
2 answers

PopupRoot from internal to PresentationFramework , so you cannot access it from your assembly. You can compare the type name with GetType().FullName , but PopupRoot is an implementation detail that may change in future versions of the framework, so I won’t rely on it.

+6
source

PopupRoot is internal, so you cannot reference it. However, if you use LogicalTreeHelper , you can find a Popup if one exists. LogicalTreeHelper will return NULL if there is no logical parent, so you need to use it in addition to the walking visual tree using VisualTreeHelper .

Here is an example of how you can use it:

 var popupRootFinder = VisualTreeHelper.GetParent((DependencyObject)your_visual_element); while (popupRootFinder != null) { var logicalRoot = LogicalTreeHelper.GetParent(popupRootFinder); if (logicalRoot is Popup) { // popup root found here break; } popupRootFinder = VisualTreeHelper.GetParent(popupRootFinder); } 
+3
source

Source: https://habr.com/ru/post/895705/


All Articles