我发现这个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指令或程序集引用?)
我该如何解决?
答案 0 :(得分:1)
根据MSDN,Windows.UI.Xaml.Input.ManipulationDeltaRoutedEventArgs
具有Delta
属性而不是DeltaManipulation
。因此,请尝试将DeltaManipulation
替换为Delta
:
if (transform != null)
{
transform.ScaleX *= e.Delta.Scale;
.....
.....
}