簡體   English   中英

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

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

我有一個自定義控件和結構,因為矩形放置在 Canvas 內,我需要在 canvas 上的觸摸移動(如觸摸選擇或觸摸第一個元素將手指移動到最后一個元素)時獲取相應的子元素源(矩形)觸摸移動事件。

上述場景在鼠標移動事件中工作正常,當鼠標懸停在它上面時,我可以獲得相應的子引用。

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#

  /// <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); ;

    }
}

在 TouchMove 上

在觸摸移動時,我總是只能獲得第一個元素參考在此處輸入圖像描述

在鼠標移動上鼠標移動我可以獲得所有相應的子參考在此處輸入圖像描述

嘗試使用 PreviewStylusMove 或 StylusMove 代替 TouchMove。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM