【发布时间】:2017-01-11 18:39:08
【问题描述】:
我在画布内有 10 个矩形,在 ManipulationDelta 事件中,我必须更改高度和宽度。它在 Windows 桌面上正常工作,但在通用 Windows 设备(手机)中操作矩形时需要一些时间。如何平滑地操作 Windows 设备中的 UI 元素。请建议我,有没有其他方法可以解决这个问题?
这是我的代码:
<Canvas Name="LayoutRoot" Width="300" Height="500">
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Red" Height="100" Width="100"/>
<Rectangle Fill="Green" Height="100" Width="100"/>
</Canvas>
private void MainPage_OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
foreach (Rectangle rectAngle in LayoutRoot.Children)
{
rectAngle.Width += e.Cumulative.Scale;
rectAngle.Height += e.Cumulative.Scale;
Canvas.SetLeft(rectAngle, LayoutRoot.Width / 2 - rectAngle.ActualWidth / 2);
Canvas.SetTop(rectAngle, LayoutRoot.Height / 2 - rectAngle.ActualHeight / 2);
}
}
【问题讨论】:
-
一个可能的解决方案是使用 Win2D 库。 Win2D 是一个带有 GPU 加速的图形渲染库。