第12章 形状、画刷和变换(2)——变换元素

来源:互联网 发布:centos 6.5 漏洞 编辑:程序博客网 时间:2024/06/07 23:01

一、变换元素概述

①变换元素可以使用RenderTransform属性实现变换。

②变换元素也可以使用LayoutTransform属性,它以相同的方式变换元素,但在布局之前执行其工作。

③在一定程度上,当设置RenderTransform属性和LayoutTransform属性时,WPF不知道它们正在被修改。特别是,变换不会影响元素的ActualHeight和ActualWidth属性,它们仍记录着变换之前的值。

二、实例代码

<Window x:Class="Drawing.RotateElement"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    Title="RotateElement" Height="314" Width="305"    >  <StackPanel>    <StackPanel  Margin="25"  Background="LightYellow">      <Button Padding="5" HorizontalAlignment="Left">        <Button.RenderTransform>          <RotateTransform Angle="35" CenterX="45" CenterY="5" />        </Button.RenderTransform>        <Button.Content>I'm rotated 35 degrees</Button.Content>      </Button>      <Button Padding="5" HorizontalAlignment="Left">I'm not</Button>    </StackPanel>    <StackPanel  Margin="25"  Background="LightYellow">      <Button Padding="5" HorizontalAlignment="Left">        <Button.LayoutTransform>          <RotateTransform Angle="35" CenterX="45" CenterY="5" />        </Button.LayoutTransform>        <Button.Content>I'm rotated 35 degrees</Button.Content>      </Button>      <Button Padding="5" HorizontalAlignment="Left">I'm not</Button>    </StackPanel>  </StackPanel></Window>
三、效果演示

0 0