My Xaml Structure :
<Canvas>
<Canvas x:Name="BackCanvas" Width="10000" Height="1000" Background="Transparent" PointerPressed="Canvas_PointerPressed"/>
<Canvas x:Name="FrontCanvas" Width="10000" Height="1000" />
</Canvas>
C# code :
private void Canvas_PointerPressed(object sender, PointerRoutedEventArgs e) { Debug.WriteLine("BackCanvas"); }
When i have structure like above, BackCanvas pointerPressed event is triggered correctly,because i didn't set background color for FrontCanvas.That's why the pointer Event is received by BackCanvas.
Incase if have Structure like below, the PointerPressed Event was not triggering...
My Xaml Code :
<Canvas>
<Canvas x:Name="BackCanvas" Width="10000" Height="1000" Background="Transparent" PointerPressed="Canvas_PointerPressed"/>
<ScrollViewer x:Name="Scroller">
<Canvas Width="5000" Height="5000"/>
</ScrollViewer>
</Canvas>
Here i'm having Scrollviewer instead of FrontCanvas.Here also i didn't set any background color for scrollviewer.But the BackCanvas PointerPressed event was not firing.
What i'm trying to acheive is i want to receive viewChange from scrollviewer and receive pointer events from BackCanvas while pointer actions.
NOTE: I can't keep the BackCanvas inside the ScrollViewer.My app structure was not like that.
My Xaml Structure :
<Canvas>
<Canvas x:Name="BackCanvas" Width="10000" Height="1000" Background="Transparent" PointerPressed="Canvas_PointerPressed"/>
<Canvas x:Name="FrontCanvas" Width="10000" Height="1000" />
</Canvas>
C# code :
private void Canvas_PointerPressed(object sender, PointerRoutedEventArgs e) { Debug.WriteLine("BackCanvas"); }
When i have structure like above, BackCanvas pointerPressed event is triggered correctly,because i didn't set background color for FrontCanvas.That's why the pointer Event is received by BackCanvas.
Incase if have Structure like below, the PointerPressed Event was not triggering...
My Xaml Code :
<Canvas>
<Canvas x:Name="BackCanvas" Width="10000" Height="1000" Background="Transparent" PointerPressed="Canvas_PointerPressed"/>
<ScrollViewer x:Name="Scroller">
<Canvas Width="5000" Height="5000"/>
</ScrollViewer>
</Canvas>
Here i'm having Scrollviewer instead of FrontCanvas.Here also i didn't set any background color for scrollviewer.But the BackCanvas PointerPressed event was not firing.
What i'm trying to acheive is i want to receive viewChange from scrollviewer and receive pointer events from BackCanvas while pointer actions.
NOTE: I can't keep the BackCanvas inside the ScrollViewer.My app structure was not like that.
Share Improve this question asked Feb 4 at 7:52 PremKumar ShanmugamPremKumar Shanmugam 4414 silver badges15 bronze badges 5 |1 Answer
Reset to default 0You can call Canvas_PointerPressed
directly:
<Canvas>
<Canvas x:Name="BackCanvas"
Width="10000"
Height="1000"
Background="Transparent" />
<ScrollViewer x:Name="Scroller"
PointerPressed="Scroller_PointerPressed"
ViewChanged="Scroller_ViewChanged">
<Canvas
Width="5000"
Height="5000" />
</ScrollViewer>
</Canvas>
private void Scroller_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Scroller_ViewChanged");
}
private void Scroller_PointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Scroller_PointerPressed");
// Setting `Handled` to `false` does not seem to work.
// e.Handled = false;
Canvas_PointerPressed(sender, e);
}
private void Canvas_PointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("BackCanvas_PointerPressed");
}
ScrollViewer
will get the pointer event automatically. If you don't change the layout, then you may try to manually call theCanvas_PointerPressed
event in the` ScrollViewer` pointer event. – Ax1le Commented Feb 4 at 8:28