UIElement.在c# WPF中,ManipulationDelta只触发一次



我想在WPF c# . net框架,VS2019中实现一个手指控制的UI。

ManipulationDelta事件被添加到矩形上,它应该连续工作。但当我测试它时,它只在我点击(触地)的那一刻触发一次。这个事件应该在我的手指按压时连续触发。

目标:显示指针在矩形区域内的位置。

XAML:

<Window x:Class="WpfApp5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp5"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid Margin="0,0,-322,-112">
<Rectangle 
ManipulationDelta="Rectangle_ManipulationDelta"
TouchMove="Rectangle_TouchMove"

Fill="#FFF4F4F5" 
HorizontalAlignment="Left" 
Height="274" Margin="162,70,0,0" 
Stroke="Black" 
VerticalAlignment="Top" 
Width="582" IsManipulationEnabled="True"/>

<TextBlock 
x:Name="textBlock" 
HorizontalAlignment="Left" 
TextWrapping="Wrap" 
VerticalAlignment="Top" 
Margin="31,26,0,0"><Run Text="TextBlock"/></TextBlock>
</Grid>

下面是打印手指位置的事件:

c#:

namespace WpfApp5{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Rectangle_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{

}
private void Rectangle_TouchMove(object sender, TouchEventArgs e)
{
textBlock.Text = "Manipulation Touch: " + Mouse.GetPosition(Application.Current.MainWindow).ToString();
}
}

}

  • 在Windows10模拟器v16和Surface Pro上测试UI

  • 不能按住鼠标右键

  • 这里有一个测试视频,用字幕描述了这个问题测试视频

  • 经过测试,像TouchMove, MouseMove, ManipulationDelta这样的事件只有当光标进入时才会被触发。元素的边界。我要在目标区域内触发这个事件。或者我应该使用另一个事件来实现这一点?

欢迎提出任何建议!谢谢你。

我发现我使用了错误的事件,我应该使用TouchMove而不是ManipulationDelta(操纵意味着操纵翻译,缩放等,这在这种情况下是不必要的)。

并且该标志应该设置为false:

IsManipulationEnabled="false"

它现在工作了!谢谢大家参与这次讨论。

最新更新