#770 –LayoutTransform和RenderTransform属性的区别(Difference Between LayoutTransform and RenderTransform)

翻译 2017年08月11日 15:22:09

原文地址:https://wpf.2000things.com/2013/03/06/770-the-difference-between-a-layouttransform-and-a-rendertransform/

当要对界面元素进行2D变换的时候,你可以使用选择LayoutTransform 属性或者RenderTransform 属性。

 - LayoutTransform 属性 是在元素布局的过程中进行变换(布局完成之前)

 - RenderTransform 属性 是在元素布局完成之后进行变换(渲染显示之前)

你可以选择其中一个进行变换,或者同时应用两个也可以。

<StackPanel Orientation="Horizontal">
    <StackPanel Orientation="Vertical">
        <Label Content="LayoutTransform"/>
        <Button Content="Push Me" Style="{StaticResource buttonStyle}"/>
        <Button Content="Push Me" Style="{StaticResource buttonStyle}">
            <Button.LayoutTransform>
                <RotateTransform Angle="20"/>
            </Button.LayoutTransform>
        </Button>
        <Button Content="Push Me" Style="{StaticResource buttonStyle}">
            <Button.LayoutTransform>
                <RotateTransform Angle="-20"/>
            </Button.LayoutTransform>
        </Button>
    </StackPanel>
    <StackPanel Orientation="Vertical">
        <Label Content="RenderTransform"/>
        <Button Content="Push Me" Style="{StaticResource buttonStyle}"/>
        <Button Content="Push Me" Style="{StaticResource buttonStyle}">
            <Button.RenderTransform>
                <RotateTransform Angle="20"/>
            </Button.RenderTransform>
        </Button>
        <Button Content="Push Me" Style="{StaticResource buttonStyle}">
            <Button.RenderTransform>
                <RotateTransform Angle="-20"/>
            </Button.RenderTransform>
        </Button>
    </StackPanel>
</StackPanel>

上面的代码中我们将6个按钮分成两列,第一列使用LayoutTransform 属性进行变换,第二列使用RenderTransform 属性进行变换。运行的结果如下图:

770-001

从图中可以发现,第一列是先进行变换,然后在将变换后的按钮进行布局计算,因此在StackPanel中,按钮会按照自己需要的控件排列。第二列是先布局,然再布局的结果是上对按钮进行变换,因此按钮所占的布局空间不会有变化,因此导致按钮有部分重叠。

相关文章推荐

WPF 中控件的变形

在WPF中,控件的形变依靠的属性包括LayoutTransform和RenderTransform。两者的区别在于调用LayoutTransform会触发一次它将触发一次新的布局系统处理过程,并强制重...

Difference Between Performance Testing, Load Testing and Stress Testing – With Examples

1) Performance Testing: Performance testing is the testing, which is performed, to ascertain how th...

Difference between start and run method in Thread – Java Tutorial

Difference between start and run method in Thread – Java Tutorial Why do one call start method of t...

python中下划线,双下划线,首尾双下划线的区别(Difference between _, __ and __xx__ in Python)

Difference between _, __ and __xx__ in Python When learning Python many people don't really under...
  • Sinchb
  • Sinchb
  • 2013-03-13 13:24
  • 2761

python中下划线,双下划线,首尾双下划线的区别(Difference between _, __ and __xx__ in Python)

Difference between _, __ and __xx__ in Python When learning Python many people don't really under...

The difference between override and overload override和overload 的区别

override(重写,覆盖)  1、方法名、参数、返回值相同。 2、子类方法不能缩小父类方法的访问权限。 3、子类方法不能抛出比父类方法更多的异常(但子类方法可以不抛出异常)。 4、存在于父...

bash与sh的区别【Difference between sh and bash】

Difference between sh and bash http://stackoverflow.com/questions/5725296/difference-between-sh-a...

What's the difference between declaring and defining something in C and C++?(C和C++中,声明和定义的区别)

原文地址:http://www.cprogramming.com/declare_vs_define.html In C and C++, there is a subtle(细微的) but im...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)