WPF(Silverlight)布局(渲染)的影响转换应用程序性能

rem*_*rem 5 silverlight wpf performance layout xaml

在设计WPF或Silverlight应用程序的UI部分时,我们可以对视觉元素应用一些显示转换(LayoutTransformRenderTransform).其中一些转变是:

  • RotateTransform
  • ScaleTransform
  • SkewTransform
  • TranslateTransform

我想知道使用这种转换在多大程度上减慢了渲染页面的速度?

更具体.例如,我在页面上有一千个简单元素,比如矩形,使用网格和一些StackPanel放入行中.如果我RotateTransform对其中的全部或部分应用,它是否会对我的应用程序的性能产生显着影响?

当然,我可以尝试看看会发生什么,但也许有一些我根本不知道的显而易见的事情.

Ric*_*key 1

您可以使用以下原型来尝试各种选项:

<Grid>
    <Grid.Resources>
        <local:Range x:Key="sampleData" Minimum="1" Maximum="900"/>
    </Grid.Resources>
    <ItemsControl ItemsSource="{StaticResource sampleData}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Rows="30" Columns="30"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding}" FontSize="8">
                    <TextBlock.LayoutTransform>
                        <RotateTransform Angle="30"/>
                    </TextBlock.LayoutTransform>
                </TextBlock>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</Grid>
Run Code Online (Sandbox Code Playgroud)

和数据生成器:

class Range : List<int>, ISupportInitialize
{
    public int Minimum { get; set; }
    public int Maximum { get; set; }

    public void BeginInit() { }

    public void EndInit()
    {
        for (int i = Minimum; i <= Maximum; i++) Add(i);
    }
}
Run Code Online (Sandbox Code Playgroud)

左上角如下所示:

变换性能

您可以通过调整窗口大小来触发布局,在我的机器上它有点慢但可用。然后您可以测试其他容器、其他转换、布局与渲染转换等,看看它们有何不同。