【问题标题】:DeltaManipulation in Windows Universal AppWindows 通用应用程序中的 DeltaManipulation
【发布时间】:2014-09-03 17:39:54
【问题描述】:

我发现这个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”的定义,并且找不到接受“Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs”类型的第一个参数的扩展方法“DeltaManipulation” (您是否缺少 using 指令或程序集引用?)

我该如何解决?

【问题讨论】:

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


    【解决方案1】:

    根据 MSDN,Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs 具有 Delta 属性,而不是 DeltaManipulation。所以尝试用Delta替换DeltaManipulation

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

    【讨论】:

    • 是的,就是这样!它适用于带有触摸屏的设备。你知道如何使用鼠标缩放吗? Control+MouseWheel 不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    • 1970-01-01
    • 2015-11-09
    • 2016-01-24
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多