如何根据
给出的触摸事件确定元素名称和其他属性Touch.FrameReported += new TouchFrameEventHandler(OnFrameReported);
private void OnFrameReported(object sender, TouchFrameEventArgs e)
{
TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null);
TouchPointCollection points = e.GetTouchPoints(null);
foreach (TouchPoint point in points)
{
if (point.Action == TouchAction.Down)
到目前为止,我已经尝试了point.TouchDevice.DirectlyOver
,但这只给了我元素类型(shape
,button
等)。我想找出x:name
。
答案 0 :(得分:1)
不幸的是,无法在运行时检索x:Name值。看到这个类似的SO帖子。
How to get x:Name value runtime
编辑: 但是,话虽如此,TouchPoint.TouchDevice.DirectlyOver是一个UIElement,可以强制转换为具有Name属性的FrameworkElement。您可以使用Name属性而不是x:Name属性,并以此方式获取您的信息。
答案 1 :(得分:1)
有一个解决方案可以尝试,让我知道^^
string name = sender.GetType().Name;
希望我帮助你^^