【问题标题】:How to know position of user press on the element?如何知道用户按下元素的位置?
【发布时间】:2013-11-19 22:38:06
【问题描述】:

我正在制作某种游戏,其中一个对象位于网格内。我希望用户能够水平或垂直按下和移动他的手指,并且对象根据他的手指的移动水平或垂直移动。

我尝试使用:

<Grid MouseEnter="Grid_MouseEnter" MouseMove="Grid_MouseMove">
    <Image Source="..." Width="50" Height="50"/>
</Grid>

但这些事件似乎毫无用处。

如何连续知道用户手指在元素 (Grid) 上的位置?谢谢

【问题讨论】:

标签: c# xaml windows-phone-7 windows-phone-8 windows-phone


【解决方案1】:

【讨论】:

    【解决方案2】:

    您应该使用画布作为拖动对象的父控件,并使用 MouseDragElementBehavior 进行拖动。 像这样的东西会有所帮助

    MouseDragElementBehavior dragBehavior1 = new MouseDragElementBehavior();
                        dragBehavior1.Attach(object to be dragged);
     dragBehavior1.ConstrainToParentBounds = true; //for restricting the object's movement outside the canvas.
    BehaviorCollection BehaviorColl1 = Interaction.GetBehaviors(object to be dragged);
    BehaviorColl1.Add(dragBehavior1);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-12
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多