C# 提高通用windows phone的性能?

C# 提高通用windows phone的性能?,c#,uwp,uwp-xaml,C#,Uwp,Uwp Xaml,画布中有10个矩形,在操纵增量事件中,我必须更改高度和宽度。它在windows桌面上正常工作,但在通用windows设备(电话)中操作矩形时需要一些时间。如何在windows设备中顺利操作UI元素。请告诉我,还有别的办法解决这个问题吗 这是我的密码: <Canvas Name="LayoutRoot" Width="300" Height="500"> <Rectangle Fill="Red" Height="100" Width="100"/> &l

画布中有10个矩形,在操纵增量事件中,我必须更改高度和宽度。它在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);
     }
}

私有void主页\u OnManipulationDelta(对象发送方,ManipulationDeltaRoutedEventArgs e)
{      
foreach(LayoutRoot.Children中的矩形)
{
矩形。宽度+=e.累积比例;
矩形。高度+=e.累积比例;
Canvas.SetLeft(矩形,LayoutRoot.Width/2-rectAngle.ActualWidth/2);
Canvas.SetTop(矩形,LayoutRoot.Height/2-rectAngle.ActualHeight/2);
}
}

您必须像TranslateTransform一样使用RenderTransform来移动元素,因为它们不是依赖属性,而是面向性能的。因此,使用画布顶部和左侧属性集RenderTransferMorigin和TranslateTransform

您将注意到性能得到了真正的提高

 private void MainPage_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        foreach (Rectangle child in LayoutRoot.Children)
        {
            child.Width += e.Cumulative.Scale;
            child.Height += e.Cumulative.Scale;

            //This is C#7 in case C#6 adapt
            if(child.RenderTransform is TranslateTransform tf)
            {
                tf.X = LayoutRoot.Width / 2 - child.ActualWidth / 2;
                tf.Y = LayoutRoot.Height / 2 - child.ActualHeight / 2;
            }
        }

    }

    private void Initialize()
    {
        var redbrush = new SolidColorBrush(Colors.Red);

        foreach (Rectangle child in LayoutRoot.Children)
        {
            child.Fill = redbrush;
            child.Height = 100;
            child.Width = 100;
            child.RenderTransformOrigin = new Point(0.5, 0.5);
            child.RenderTransform = new TranslateTransform();
        }
    }

一种可能的解决方案是使用Win2D库。Win2D是一个带有GPU加速的图形渲染库。谢谢。那么它在windows桌面上是如何工作的呢?为什么windows设备需要时间?@Santhiya手机的低功耗和处理能力意味着性能将低于台式机。