首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何累加拖动Ellipse对象?

如何累加拖动Ellipse对象?
EN

Stack Overflow用户
提问于 2012-03-18 02:28:24
回答 1查看 720关注 0票数 0

我遵循了一个教程,并在XAML文件中定义了一个位于屏幕中央的Ellipse对象,该对象在Ellipse.RenderTransform节点中包含一个TranslateTransform节点,如下所示:

代码语言:javascript
复制
<Ellipse
  x:Name="theEllipse"
  Fill="White"
  Width="200"
  Height="200">
  <Ellipse.RenderTransform>
    <TranslateTransform x:Name="theMover" />
  </Ellipse.RenderTransform>
</Ellipse>

在后面的代码中,我向Ellipse添加了一个ManipulationDelta事件处理程序,如下所示:

代码语言:javascript
复制
public MainPage()
{
// other stuff
theEllipse.ManipulationDelta
  += new EventHandler<ManipulationDeltaEventArgs>(theEllipse_ManipulationDelta);
}

void theEllipse_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
theMover.X = e.CumulativeManipulation.Translation.X;
theMover.Y = e.CumulativeManipulation.Translation.Y;
}

因此,我可以向下按下Ellipse并将其从起始位置拖动。然而,我发现当我松开Ellipse并再次按下它时,Ellipse跳跃并开始从它的初始位置而不是它的当前位置拖动。为什么会这样呢?当我第二次拖动椭圆时,无论它在哪里,我该如何定义我的拖动操作是累积的呢?

EN

回答 1

Stack Overflow用户

发布于 2013-01-09 18:40:36

不确定你是否已经修复了这个问题,但是这里有一个解决方案:

为manipulationStarting添加事件处理程序,并将manipulationContainer设置为其母对象。

代码语言:javascript
复制
<Window x:Class="TempProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="768" Width="640"
    ManipulationStarting="window_ManipulationStarting"
      ManipulationDelta="window_ManipulationDelta"
     >
<Grid x:Name="canvas">
    <Ellipse
x:Name="theEllipse"
Fill="Black"
Width="200"
Height="200"
IsManipulationEnabled="True">
<Ellipse.RenderTransform>
            <TranslateTransform x:Name="theMover" />
        </Ellipse.RenderTransform>
    </Ellipse>
</Grid>
</Window>

代码语言:javascript
复制
private void window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
    {
        theMover.X = e.CumulativeManipulation.Translation.X;
        theMover.Y = e.CumulativeManipulation.Translation.Y;
        e.Handled = true;
    }

    private void window_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
    {
        e.ManipulationContainer = canvas;
        e.Handled = true;
    }

其中"canvas“是包含椭圆的网格布局的名称。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9752627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档