Windows Universal App中的DeltaManipulation

时间:2014-08-09 10:58:44

标签: c# windows-8.1 windows-phone-8.1 win-universal-app

我发现这个example接缝正是我需要的。但它不适用于通用应用程序。

的Xaml:

<Rectangle Name="TestRectangle"
Width="200"
Height="200"
Fill="Blue" 
ManipulationMode="All" />

C#:

public MainPage()
{
    InitializeComponent();

    // Add handler for the ManipulationDelta event
    TestRectangle.ManipulationDelta += new ManipulationDeltaEventHandler((sender, e) =>
    {
        UIElement element = sender as UIElement;
        CompositeTransform transform = element.RenderTransform as CompositeTransform;
        if (transform != null)
        {
            transform.ScaleX *= e.DeltaManipulation.Scale;
            transform.ScaleY *= e.DeltaManipulation.Scale;
            transform.Rotation += e.DeltaManipulation.Rotation * 180 / Math.PI;
            transform.TranslateX += e.DeltaManipulation.Translation.X;
            transform.TranslateY += e.DeltaManipulation.Translation.Y;
        }
    });

    TestRectangle.RenderTransform = new CompositeTransform();
}

这是错误:

  

'Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs'不包含'DeltaManipulation'的定义,也没有扩展方法'DeltaManipulation'接受类型'Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs'的第一个参数(您是否缺少using指令或程序集引用?)

我该如何解决?

1 个答案:

答案 0 :(得分:1)

根据MSDN,Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs具有Delta属性而不是DeltaManipulation。因此,请尝试将DeltaManipulation替换为Delta

if (transform != null)
{
    transform.ScaleX *= e.Delta.Scale;
    .....
    .....
}