简体   繁体   English

需要在 Touch Move 事件上获取子元素(e.Source)

[英]Need to get child element(e.Source) on Touch Move event

I have an custom control and structure as Rectangles are placed inside the Canvas, I need to get the corresponding child element source(rectangle) while touch move(like touch selection or touch the first element move the finger to last element) on the canvas in touch move event.我有一个自定义控件和结构,因为矩形放置在 Canvas 内,我需要在 canvas 上的触摸移动(如触摸选择或触摸第一个元素将手指移动到最后一个元素)时获取相应的子元素源(矩形)触摸移动事件。

The above scenario working fine in Mouse Move event where I can get corresponding child reference when mouse over on it.上述场景在鼠标移动事件中工作正常,当鼠标悬停在它上面时,我可以获得相应的子引用。

Xaml Code Xaml 代码

 <Grid>
    <Canvas TouchMove="Canvas_TouchMove" MouseMove="Canvas_MouseMove" >
        <WrapPanel >
            <Rectangle Fill="Red" Name="Red" 
             Width="200" Height="200" 
             IsManipulationEnabled="true" />
            <Rectangle Fill="Blue" Name="Blue"
             Width="200" Height="200" 
             IsManipulationEnabled="true" />
            <Rectangle Fill="Yellow" Name="Yellow"
             Width="200" Height="200" 
             IsManipulationEnabled="true" />
            <Rectangle Fill="Green" Name="Green"
             Width="200" Height="200" 
             IsManipulationEnabled="true" />
            <Rectangle Fill="Pink" Name="Pink"
             Width="200" Height="200" 
             IsManipulationEnabled="true" />
            <Rectangle Fill="Red" Name="manRect5"
             Width="200" Height="200" 
             IsManipulationEnabled="true" />
        </WrapPanel>

    </Canvas>
</Grid>

C# C#

  /// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Canvas_TouchMove(object sender, TouchEventArgs e)
    {
        Console.WriteLine((e.Source as Rectangle).Name); ;
    }


    private void Canvas_MouseMove(object sender, MouseEventArgs e)
    {
        Console.WriteLine((e.Source as Rectangle).Name); ;

    }
}

On TouchMove在 TouchMove 上

On touch move I can get only first element reference always在触摸移动时,我总是只能获得第一个元素参考在此处输入图像描述

On Mouse Move On mouse move I can get all corresoponding child refference在鼠标移动上鼠标移动我可以获得所有相应的子参考在此处输入图像描述

Try using PreviewStylusMove or StylusMove instead of TouchMove.尝试使用 PreviewStylusMove 或 StylusMove 代替 TouchMove。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM