1

I'm trying to convert an library from wpf to uwp. I'm almost done but now there is the LogicalTreeViewHelper which doesn't exist in UWP anymore.

does anyone know how to replace it in uwp?

var parent = LogicalTreeHelper.GetParent(MyDependencyObject);
Kevin Li
  • 2,258
  • 1
  • 9
  • 18
Tobias Koller
  • 2,116
  • 4
  • 26
  • 46

2 Answers2

4

In UWP, you should use the VisualTreeHelper class instead.

There are quite a few toolkits and helpers around to do this, I personally have my Cimbalino Toolkit which provides direct extension methods so you could just do:

var parent = MyDependencyObject.GetVisualParent();

For this to work, you can either go the simple route add the NuGet package to your solution or just take the bits you need from the source code

Pedro Lamas
  • 7,185
  • 4
  • 27
  • 35
  • thanks. I took a look inside the github Project and all what this function does is returning VisualTreeHelper.GetParent(dependencyObject); So in my case I dont Need this Extension-method. – Tobias Koller Mar 18 '17 at 08:32
  • the .Parent property on FrameworkElement should give you the LogicalParent rather than the VisualParent, if you need it. – Johnny Westlake Jul 07 '17 at 13:32
0

You can also try using the UWP Toolkit to get some handy extensions for traversing the Visual Tree (Microsoft.Toolkit.Uwp.UI nuget package)

https://github.com/Microsoft/UWPCommunityToolkit

Maximus
  • 1,441
  • 14
  • 38