【发布时间】:2021-10-10 19:44:46
【问题描述】:
我有一个带有网格的简单页面。网格包含一个 TextBlock。我在页面中添加了 PointerWheelChanged 的处理程序。
由于某种原因,该事件仅在鼠标指针位于 TextBlock 内而不是其他任何地方时调用。
我尝试将事件添加到网格中。
我的代码:
<Page
x:Class="App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
PointerWheelChanged="Page_PointerWheelChanged">
<Grid>
<TextBlock HorizontalAlignment="Center" Text="TextBlock" TextWrapping="Wrap" VerticalAlignment="Center" Height="980" Width="1480" x:Name="test" FontSize="72"/>
</Grid>
</Page>
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
namespace App {
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void Page_PointerWheelChanged(object sender, PointerRoutedEventArgs e) {
var delta = e.GetCurrentPoint((UIElement)sender).Properties.MouseWheelDelta;
test.Text = delta.ToString();
}
}
}
我最初是在一个更复杂的应用程序中发现的。这是一个简单的应用程序,我尝试在其中重现此行为。
【问题讨论】: