Windows通用应用程序中的deltamanulation

本文关键字:deltamanulation 应用程序 Windows | 更新日期: 2023-09-27 18:17:18

我发现这个例子似乎正是我所需要的。但它不能在通用应用程序中工作。

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'不包含' deltaman操作法'的定义,也没有扩展方法' deltaman操作法'接受类型为'Windows.UI.Xaml.Input '的第一个参数。可以找到ManipulationDeltaRoutedEventArgs'(您是否缺少using指令或程序集引用?)

我该如何修复它?

Windows通用应用程序中的deltamanulation

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

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