代码改变世界

WP7备注(16)(Transform)

2011-04-28 14:28  血糯米Otomii  阅读(317)  评论(1编辑  收藏  举报

基本变化实例:

常用Transform的演示

<TextBlock>
<TextBlock.RenderTransform>
<ScaleTransform ScaleX="2" ScaleY="3" />
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock Text="Transform Experiment"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"
CenterX="0" CenterY="0" />
<SkewTransform AngleX="0" AngleY="0"
CenterX="0" CenterY="0" />
<RotateTransform Angle="0"
CenterX="0" CenterY="0" />
<TranslateTransform X="0" Y="0" />
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>

CompositeTransform的使用:

CompositeTransform提供了一种在Code中进行手动添加变换的支持:

<TextBlock Name="txtblk">
<TextBlock.RenderTransform>
<CompositeTransform />
</TextBlock.RenderTransform>
</TextBlock>
CompositeTransform xform = txtblk.RenderTransform as CompositeTransform;
xform.CenterX = textSize.Height / 2;
xform.CenterY = textSize.Height / 2;
xform.ScaleX = scale;
xform.ScaleY = scale;
xform.Rotation = angle - 90;
xform.TranslateX = gridCenter.X - textSize.Height / 2;
xform.TranslateY = gridCenter.Y - textSize.Height / 2;

同时程序也提供了一种和程序帧一起同步更新变换的方式:

CompositionTarget.Rendering += OnCompositionTargetRendering;

void OnCompositionTargetRendering(object sender, EventArgs args)
{
TimeSpan renderingTime = (args as RenderingEventArgs).RenderingTime;
//更新变换属性
}