2

I have a Canvas with many LineGeometry objects in it and want to let the user select a specific LineGeometry and interact with it. Keying off a Tapped callback, I'm using the visualTreeHelper, but it appears I'm getting an empty collection back. This is for the newer windows 10 universal apps.

XAML:

<Border x:Name="elementsArea" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  BorderBrush="Black" BorderThickness="2" Margin="12" Tapped="tapped">
  <Path  Stroke="Black">
    <Path.Data>
      <GeometryGroup x:Name="DrawChildren">
        <LineGeometry StartPoint="-1,0" EndPoint="100,100" />  
      </GeometryGroup>
    </Path.Data> 
   </Path> 
</Border>

Here is the C# code:

private void tapped(object sender, TappedRoutedEventArgs e)
{
    // Retrieve the coordinate of the mouse position.
    Point pt = e.GetPosition((UIElement)sender);
    var result = VisualTreeHelper.FindElementsInHostCoordinates(pt, elementsArea);
    if (result != null)
    {
        foreach (var i in result)
        {
            try
            {  // never gets here
                var l = i as UIElement;
            }
            catch (Exception ee)
            {
            }
        }
    }
}
Francis Ducharme
  • 4,848
  • 6
  • 43
  • 81
nmishr
  • 287
  • 3
  • 6

0 Answers0