【发布时间】:2021-10-11 12:35:30
【问题描述】:
我正在寻找一种方法来拦截所有事件,例如父级的 PointerReleased。
我的问题是我无法拦截 ScrollViewer 的父 PointerReleased 事件。
我想用手指将手指(光标)放入 ScrollViewer 移动 100 像素,然后松开;它应该像 Scrollviewer.IsHitTestVisible=false 一样工作,并将所有事件接收到 outerStack(scrollerviewer 的父级),但 scrollviewer 应该像 IsHitTestVisible=true 一样工作,并继续将所有相关事件获取到自身(scrollviewer)及其子级(scrollviewer 子级,如 innerStack )。
我收到以下日志
innerStack_PointerPressed
scrollView_PointerPressed
outerStack_PointerPressed
CoreWindow_PointerPressed
但我期待看到这个
innerStack_PointerPressed
scrollView_PointerPressed
outerStack_PointerPressed
CoreWindow_PointerPressed
outerStack_PointerReleased
CoreWindow_PointerReleased
有代码示例
<Page
x:Class="App9.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel x:Name="outerStack"
Background="Red"
Padding="40"
PointerPressed="outerStack_PointerPressed"
PointerReleased="outerStack_PointerReleased">
<ScrollViewer x:Name="scrollView"
Background="Blue"
Padding="40"
PointerPressed="scrollView_PointerPressed"
PointerReleased="scrollView_PointerReleased"
VerticalScrollBarVisibility="Visible"
VerticalScrollMode="Enabled"
HorizontalScrollBarVisibility="Visible"
HorizontalScrollMode="Enabled"
Height="500">
<StackPanel x:Name="innerStack"
Background="Green"
Padding="40"
PointerPressed="innerStack_PointerPressed"
PointerReleased="innerStack_PointerReleased">
<TextBlock Text="A" FontSize="100"/>
<TextBlock Text="B" FontSize="100"/>
<TextBlock Text="C" FontSize="100"/>
<TextBlock Text="D" FontSize="100"/>
<TextBlock Text="E" FontSize="100"/>
<TextBlock Text="F" FontSize="100"/>
<TextBlock Text="G" FontSize="100"/>
<TextBlock Text="H" FontSize="100"/>
<TextBlock Text="I" FontSize="100"/>
<TextBlock Text="J" FontSize="100"/>
<TextBlock Text="K" FontSize="100"/>
<TextBlock Text="L" FontSize="100"/>
<TextBlock Text="M" FontSize="100"/>
<TextBlock Text="N" FontSize="100"/>
<TextBlock Text="O" FontSize="100"/>
<TextBlock Text="P" FontSize="100"/>
<TextBlock Text="Q" FontSize="100"/>
<TextBlock Text="R" FontSize="100"/>
<TextBlock Text="S" FontSize="100"/>
<TextBlock Text="T" FontSize="100"/>
<TextBlock Text="U" FontSize="100"/>
<TextBlock Text="V" FontSize="100"/>
<TextBlock Text="W" FontSize="100"/>
<TextBlock Text="X" FontSize="100"/>
<TextBlock Text="Y" FontSize="100"/>
<TextBlock Text="Z" FontSize="100"/>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Page>
using System.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
namespace App9
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
Window.Current.CoreWindow.PointerPressed += CoreWindow_PointerPressed;
Window.Current.CoreWindow.PointerReleased += CoreWindow_PointerReleased;
}
private void CoreWindow_PointerPressed(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.PointerEventArgs args)
{
Debug.WriteLine("CoreWindow_PointerPressed");
}
private void CoreWindow_PointerReleased(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.PointerEventArgs args)
{
Debug.WriteLine("CoreWindow_PointerReleased");
}
private void outerStack_PointerPressed(object sender, PointerRoutedEventArgs e)
{
Debug.WriteLine("outerStack_PointerPressed");
}
private void outerStack_PointerReleased(object sender, PointerRoutedEventArgs e)
{
Debug.WriteLine("outerStack_PointerReleased");
}
private void scrollView_PointerPressed(object sender, PointerRoutedEventArgs e)
{
Debug.WriteLine("scrollView_PointerPressed");
}
private void scrollView_PointerReleased(object sender, PointerRoutedEventArgs e)
{
Debug.WriteLine("scrollView_PointerReleased");
}
private void innerStack_PointerPressed(object sender, PointerRoutedEventArgs e)
{
Debug.WriteLine("innerStack_PointerPressed");
}
private void innerStack_PointerReleased(object sender, PointerRoutedEventArgs e)
{
Debug.WriteLine("innerStack_PointerReleased");
}
}
}
【问题讨论】:
标签: wpf uwp xamarin.uwp