原文:重新想象 Windows 8 Store Apps (14) - 控件 UI: RenderTransform, Projection, Clip, UseLayoutRounding

[源码下载]

重新想象 Windows 8 Store Apps (14) - 控件 UI: RenderTransform, Projection, Clip, UseLayoutRounding

作者:webabcd

介绍
重新想象 Windows 8 Store Apps 之 控件 UI

  • RenderTransform - 变换(用于做位移,旋转,缩放,扭曲等变换)
  • Projection - 映射
  • Clip - 剪裁并显示 UIElement 的指定区域
  • UseLayoutRounding - 是否使用完整像素布局

示例
1、演示 RenderTransform 的应用
Controls/UI/RenderTransform.xaml

<Page
x:Class="XamlDemo.Controls.UI.RenderTransform"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlDemo.Controls.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<Grid Margin="120 0 0 0"> <!--
RenderTransform - 变换(用于做位移,旋转,缩放,扭曲等变换)
--> <Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Width="200" Height="100" StrokeDashArray="3,1" Stroke="Blue" StrokeThickness="3" />
<Rectangle Width="200" Height="100" Fill="Yellow" Stroke="Red" StrokeThickness="3" Opacity="0.3">
<Rectangle.RenderTransform> <!--RotateTransform - 旋转变换(顺时针)-->
<!--
Angle - 旋转角度。默认值 0
CenterX - 旋转中心点的 X 轴坐标。默认值 0
CenterY - 旋转中心点的 Y 轴坐标。默认值 0
-->
<RotateTransform Angle="15" CenterX="100" CenterY="50" /> </Rectangle.RenderTransform>
</Rectangle>
</Grid> <Grid Margin="400 0 0 0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Width="200" Height="100" StrokeDashArray="3,1" Stroke="Blue" StrokeThickness="3" />
<!--
RenderTransformOrigin - 位置变换的中心点
-->
<Rectangle Width="200" Height="100" Fill="Yellow" Stroke="Red" StrokeThickness="3" Opacity="0.3" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform>
<RotateTransform Angle="15" />
</Rectangle.RenderTransform>
</Rectangle>
</Grid> <Grid Margin="800 0 0 0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Width="200" Height="100" StrokeDashArray="3,1" Stroke="Blue" StrokeThickness="3" />
<Rectangle Width="200" Height="100" Fill="Yellow" Stroke="Red" StrokeThickness="3" Opacity="0.3">
<Rectangle.RenderTransform> <!--TranslateTransform - 平移变换-->
<!--
X - 水平方向上移动的距离。默认值 0
Y - 垂直方向上移动的距离。默认值 0
-->
<TranslateTransform X="100" Y="10" /> </Rectangle.RenderTransform>
</Rectangle>
</Grid> <Grid Margin="0 200 0 0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Width="200" Height="100" StrokeDashArray="3,1" Stroke="Blue" StrokeThickness="3" />
<Rectangle Width="200" Height="100" Fill="Yellow" Stroke="Red" StrokeThickness="3" Opacity="0.3">
<Rectangle.RenderTransform> <!--ScaleTransform - 缩放变换-->
<!--
ScaleX - X 轴方向上缩放的倍数。默认值 1
ScaleY - Y 轴方向上缩放的倍数。默认值 1
CenterX - 缩放中心点的 X 轴坐标。默认值 0
CenterY - 缩放中心点的 Y 轴坐标。默认值 0
-->
<ScaleTransform ScaleX="1.1" ScaleY="1.3" CenterX="100" CenterY="50" /> </Rectangle.RenderTransform>
</Rectangle>
</Grid> <Grid Margin="400 200 0 0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Width="200" Height="100" StrokeDashArray="3,1" Stroke="Blue" StrokeThickness="3" />
<Rectangle Width="200" Height="100" Fill="Yellow" Stroke="Red" StrokeThickness="3" Opacity="0.3">
<Rectangle.RenderTransform> <!--SkewTransform - 扭曲变换(典型应用:在 二维 对象中模拟 三维 深度)-->
<!--
CenterX - 扭曲中心点的 X 轴坐标。默认值 0
CenterY - 扭曲中心点的 Y 轴坐标。默认值 0
AngleX - X 轴扭曲角度,Y 轴绕原点旋转(逆时针)。CenterX 对此值所产生的呈现结果没有影响。默认值 0
AngleY - Y 轴扭曲角度,X 轴绕原点旋转(顺时针)。CenterY 对此值所产生的呈现结果没有影响。默认值 0
-->
<SkewTransform AngleX="30" AngleY="5" CenterX="0" CenterY="0" /> </Rectangle.RenderTransform>
</Rectangle>
</Grid> <Grid Margin="800 200 0 0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Width="200" Height="100" StrokeDashArray="3,1" Stroke="Blue" StrokeThickness="3" />
<Rectangle Width="200" Height="100" Fill="Yellow" Stroke="Red" StrokeThickness="3" Opacity="0.3">
<Rectangle.RenderTransform> <!--TransformGroup - 多个 Transform 组成的复合变换-->
<TransformGroup>
<TranslateTransform X="100" Y="10" />
<RotateTransform Angle="15" CenterX="100" CenterY="50" />
</TransformGroup> </Rectangle.RenderTransform>
</Rectangle>
</Grid> <!--
CompositeTransform - 将多种变换方式合而为一
CenterX - 变换中心点的 X 坐标
CenterY - 变换中心点的 Y 坐标
Rotation - 顺时针旋转角度
ScaleX - 沿 X 轴方向上的缩放比例
ScaleY - 沿 Y 轴方向上的缩放比例
SkewX - X 轴扭曲角度
SkewY - Y 轴扭曲角度
TranslateX - 沿 X 轴方向上的平移距离
TranslateY - 沿 Y 轴方向上的平移距离
-->
<Grid Margin="0 400 0 0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Width="200" Height="100" StrokeDashArray="3,1" Stroke="Blue" StrokeThickness="3" />
<Rectangle Width="200" Height="100" Fill="Yellow" Stroke="Red" StrokeThickness="3" Opacity="0.3">
<Rectangle.RenderTransform>
<CompositeTransform SkewX="30" Rotation="60" ScaleX="0.6" ScaleY="0.3" />
</Rectangle.RenderTransform>
</Rectangle>
</Grid> <!--
MatrixTransform - 仿射矩阵变换 |X| |M11(默认值 1) M21(默认值 0) 0|
|Y| = |x y 1| * |M12(默认值 0) M22(默认值 1) 0|
|1| |OffsetX(默认值 0) OffsetY(默认值 0) 1| X = x * M11 + y * M12 + OffsetX
Y = x * M21 + y * M22 + OffsetY 利用 MatrixTransform 实现平移、旋转、缩放、扭曲的 Demo 详见 http://www.cnblogs.com/webabcd/archive/2008/11/03/1325150.html
-->
<Grid Margin="400 400 0 0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Width="200" Height="100" StrokeDashArray="3,1" Stroke="Blue" StrokeThickness="3" />
<Rectangle Width="200" Height="100" Fill="Yellow" Stroke="Red" StrokeThickness="3" Opacity="0.3">
<Rectangle.RenderTransform>
<!--
m11, m12, m21, m22, offsetX, offsetY
-->
<MatrixTransform Matrix="1, 0.5, 0, 1, 30, 10" />
</Rectangle.RenderTransform>
</Rectangle>
</Grid> </Grid>
</Grid>
</Page>

2、演示 Projection 的应用
Controls/UI/Projection.xaml

<Page
x:Class="XamlDemo.Controls.UI.Projection"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlDemo.Controls.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<Grid Margin="120 0 0 0"> <!--
Projection - 映射 PlaneProjection - 平面映射,使 UIElement 实现 3D 效果
RotationX, RotationY, RotationZ - 绕 X轴, Y轴, Z轴 旋转的角度
CenterOfRotationX, CenterOfRotationY, CenterOfRotationZ - X轴, Y轴, Z轴 旋转中心点的相对位置(CenterOfRotationX, CenterOfRotationY 默认值为 0.5 , CenterOfRotationZ 默认值为 0)
GlobalOffsetX, GlobalOffsetY, GlobalOffsetZ - 沿 X轴, Y轴, Z轴 的偏移量,此 3 个方向与屏幕的 3 个方向相同
LocalOffsetX, LocalOffsetY, LocalOffsetZ - 沿 X轴, Y轴, Z轴 的偏移量,此 3 个方向与相关的 UIElement 当前的 3 个方向相同 Matrix3DProjection - 矩阵映射
--> <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Rectangle Width="200" Height="100" StrokeDashArray="3,1" Stroke="Blue" StrokeThickness="3" />
<Rectangle Width="200" Height="100" Fill="Yellow" Stroke="Red" StrokeThickness="3" Opacity="0.3">
<Rectangle.Projection>
<PlaneProjection x:Name="planeProjection" />
</Rectangle.Projection>
</Rectangle>
</Grid> <StackPanel>
<TextBlock FontSize="14.667" Text="RotationX:" Margin="0 10 0 0" />
<Slider Width="150" Minimum="0" Maximum="360" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 -10 0 0"
Value="{Binding ElementName=planeProjection, Path=RotationX, Mode=TwoWay}" /> <TextBlock FontSize="14.667" Text="RotationY:" Margin="0 -10 0 0" />
<Slider Width="150" Minimum="0" Maximum="360" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 -10 0 0"
Value="{Binding ElementName=planeProjection, Path=RotationY, Mode=TwoWay}" /> <TextBlock FontSize="14.667" Text="RotationZ:" Margin="0 -10 0 0" />
<Slider Width="150" Minimum="0" Maximum="360" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 -10 0 0"
Value="{Binding ElementName=planeProjection, Path=RotationZ, Mode=TwoWay}" /> <TextBlock FontSize="14.667" Text="LocalOffsetX:" Margin="0 -10 0 0" />
<Slider Width="150" Minimum="-150" Maximum="150" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 -10 0 0"
Value="{Binding ElementName=planeProjection, Path=LocalOffsetX, Mode=TwoWay}" /> <TextBlock FontSize="14.667" Text="LocalOffsetY:" Margin="0 -10 0 0" />
<Slider Width="150" Minimum="-150" Maximum="150" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 -10 0 0"
Value="{Binding ElementName=planeProjection, Path=LocalOffsetY, Mode=TwoWay}" /> <TextBlock FontSize="14.667" Text="LocalOffsetZ:" Margin="0 -10 0 0" />
<Slider Width="150" Minimum="-150" Maximum="150" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 -10 0 0"
Value="{Binding ElementName=planeProjection, Path=LocalOffsetZ, Mode=TwoWay}" /> <TextBlock FontSize="14.667" Text="GlobalOffsetX:" Margin="0 -10 0 0" />
<Slider Width="150" Minimum="-150" Maximum="150" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 -10 0 0"
Value="{Binding ElementName=planeProjection, Path=GlobalOffsetX, Mode=TwoWay}" /> <TextBlock FontSize="14.667" Text="GlobalOffsetY:" Margin="0 -10 0 0" />
<Slider Width="150" Minimum="-150" Maximum="150" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 -10 0 0"
Value="{Binding ElementName=planeProjection, Path=GlobalOffsetY, Mode=TwoWay}" /> <TextBlock FontSize="14.667" Text="GlobalOffsetZ:" Margin="0 -10 0 0" />
<Slider Width="150" Minimum="-150" Maximum="150" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 -10 0 0"
Value="{Binding ElementName=planeProjection, Path=GlobalOffsetZ, Mode=TwoWay}" />
</StackPanel> </Grid>
</Grid>
</Page>

3、演示 Clip 的应用
Controls/UI/Clip.xaml

<Page
x:Class="XamlDemo.Controls.UI.Clip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlDemo.Controls.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="120 0 0 0"> <Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Width="200" Height="100" Fill="Red" />
<Rectangle Width="200" Height="100" Fill="Green"> <!--
Clip - 剪裁并显示 UIElement 的指定区域 注:win8 中只能通过 RectangleGeometry 剪裁 UIElement
-->
<Rectangle.Clip>
<RectangleGeometry Rect="10 10 50 50" />
</Rectangle.Clip>
</Rectangle>
</Grid> </StackPanel>
</Grid>
</Page>

4、演示 UseLayoutRounding 的应用
Controls/UI/UseLayoutRounding.xaml

<Page
x:Class="XamlDemo.Controls.UI.UseLayoutRounding"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamlDemo.Controls.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="120 0 0 0"> <!--
UseLayoutRounding - 是否使用完整像素布局。默认值为 true
举例:
1、如果设置了Margin="1.6"(非完整像素)
2、那么UseLayoutRounding="true"时,则容器的外边距不相等;UseLayoutRounding="false"时,则容器的外边距相等
-->
<Grid Width="200" Height="200" HorizontalAlignment="Left" UseLayoutRounding="True">
<Border BorderBrush="#FF884909" Background="#FFFBECA3" BorderThickness="1"></Border>
<Border BorderBrush="#FF884909" Background="#FFFBECA3" BorderThickness="1" Margin="1.6"></Border>
</Grid> <Grid Width="200" Height="200" Margin="0 10 0 0" HorizontalAlignment="Left" UseLayoutRounding="False">
<Border BorderBrush="#FF884909" Background="#FFFBECA3" BorderThickness="1"></Border>
<Border BorderBrush="#FF884909" Background="#FFFBECA3" BorderThickness="1" Margin="1.6"></Border>
</Grid> </StackPanel>
</Grid>
</Page>

OK
[源码下载]

重新想象 Windows 8 Store Apps (14) - 控件 UI: RenderTransform, Projection, Clip, UseLayoutRounding的更多相关文章

  1. 重新想象 Windows 8 Store Apps (15) - 控件 UI: 字体继承, Style, ControlTemplate, SystemResource, VisualState, VisualStateManager

    原文:重新想象 Windows 8 Store Apps (15) - 控件 UI: 字体继承, Style, ControlTemplate, SystemResource, VisualState ...

  2. 重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree

    原文:重新想象 Windows 8 Store Apps (17) - 控件基础: Measure, Arrange, GeneralTransform, VisualTree [源码下载] 重新想象 ...

  3. 重新想象 Windows 8 Store Apps (16) - 控件基础: 依赖属性, 附加属性, 控件的继承关系, 路由事件和命中测试

    原文:重新想象 Windows 8 Store Apps (16) - 控件基础: 依赖属性, 附加属性, 控件的继承关系, 路由事件和命中测试 [源码下载] 重新想象 Windows 8 Store ...

  4. 重新想象 Windows 8 Store Apps (13) - 控件之 SemanticZoom

    原文:重新想象 Windows 8 Store Apps (13) - 控件之 SemanticZoom [源码下载] 重新想象 Windows 8 Store Apps (13) - 控件之 Sem ...

  5. 重新想象 Windows 8 Store Apps (12) - 控件之 GridView 特性: 拖动项, 项尺寸可变, 分组显示

    原文:重新想象 Windows 8 Store Apps (12) - 控件之 GridView 特性: 拖动项, 项尺寸可变, 分组显示 [源码下载] 重新想象 Windows 8 Store Ap ...

  6. 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView

    原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...

  7. 重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom

    原文:重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom [源码下载] ...

  8. 重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础

    原文:重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础 [源码下载] 重新想象 Windows 8 Store Apps (9) - 控件之 Sc ...

  9. 重新想象 Windows 8 Store Apps (7) - 控件之布局控件: Canvas, Grid, StackPanel, VirtualizingStackPanel, WrapGrid, VariableSizedWrapGrid

    原文:重新想象 Windows 8 Store Apps (7) - 控件之布局控件: Canvas, Grid, StackPanel, VirtualizingStackPanel, WrapGr ...

随机推荐

  1. MariaDb数据库管理系统学习(二)使用HeidiSQL数据库图形化界面管理工具

    HeidiSQL 是一款用于简单化的 MySQL server和数据库管理的图形化界面.该软件同意你浏览你的数据库,管理表,浏览和编辑记录,管理用户权限等等.此外,你能够从文本文件导入数据,执行 SQ ...

  2. [初探iOS开发]storyboard的使用

    storyboard的目的是为了方便的设计程序view之间的关系,使得程序员把精力都放到核心业务逻辑之上.

  3. Java 建立mysql数据库连接的语句

    每次在面试时被问到jdbc的数据路链接过程都卡着,这次不怕了,背会了... 第一个,比较粗糙的 try{   Class.forName("com.mysql.jdbc.Driver&quo ...

  4. C++ 指针—02 指针与引用的对照

    ★同样点: ●都是地址的概念: 指针指向一块内存,它的内容是所指内存的地址:而引用则是某块内存的别名. ★不同点: ●指针是一个实体,而引用仅是个别名: ●引用仅仅能在定义时被初始化一次,之后不可变: ...

  5. ORACLE数据库常见问题汇总

    提交事务的时候提示(数据库被一个用户锁住的解决方法) select object_id,session_id,locked_mode from v$locked_object; select t2.u ...

  6. 对称加密算法DES,3重DES,TDEA,Blowfish,RC5,IDEA,AES。

    对称加密算法:DES,3重DES,TDEA,Blowfish,RC5,IDEA,AES. 1.对称加密算法 1.1 定义 对称加密算法是应用较早的加密算法,技术成熟.在对称加密算法中,数据发信方将明文 ...

  7. 重温委托(delegate)和事件(event)

    1.delegate是什么 某种意义上来讲,你可以把delegate理解成C语言中的函数指针,它允许你传递一个类A的方法m给另一个类B的对象,使得类B的对象能够调用这个方法m,说白了就是可以把方法当作 ...

  8. 基于WEB 的认证防火墙的设计

    项目要求: 1.  采用Linux iptbles作为接入防火墙,默认放行所以访问入口的80端口 2.  访问者通过http://x.x.x.x 访问防火墙的认证系统,进行账号的登陆操作,同时系统对用 ...

  9. ORA-00210 ORA-15001 ORA-15055 ORA-01031: insufficient privileges

    ORA-00210: cannot open the specified control file ORA-00202: control file: &apos;+DATA/posdb/con ...

  10. MapReduce 异常 LongWritable cannot be cast to Text

    有一个txt文件,内容格公式是这样的: 深圳订做T恤 5729944 深圳厂家t恤批发 5729945 深圳定做文化衫 5729944 文化衫厂家 5729944 订做文化衫 5729944 深圳t恤 ...