首页 > 其他分享 >WPF/Silverlight中图形的平移,缩放,旋转,倾斜变换演示

WPF/Silverlight中图形的平移,缩放,旋转,倾斜变换演示

时间:2023-02-28 11:04:19浏览次数:42  
标签:Silverlight 演示 缩放 XAML 从略 winfx 图形 WPF


为方便描述, 这里仅以正方形来做演示, 其他图形从略。

运行时效果图:

WPF/Silverlight中图形的平移,缩放,旋转,倾斜变换演示_setter



XAML代码:

// Transform.XAML

<Canvas Width="700" Height="700" xmlns="​​http://schemas.microsoft.com/winfx/2006/xaml/presentation​​"
xmlns:x="​​http://schemas.microsoft.com/winfx/2006/xaml​​">
<Canvas.Resources>
<DrawingBrush x:Key="MyGridBrushResource" Viewport="0,0,100,100" ViewportUnits="Absolute" TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<!--横线-->
<GeometryDrawing Geometry="M0,1 L10,1 M0,2 L10,2 M0,3 L10,3 M0,4 L10,4 M0,5 L10,5 M0,6 L10,6 M0,7 L10,7 M0,8 L10,8 M0,9 L10,9">
<GeometryDrawing.Pen>
<Pen Thickness="0.1" Brush="#CCCCFF" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<!-- 横线100整数倍 -->
<GeometryDrawing Geometry="M0,0 L10,0">
<GeometryDrawing.Pen>
<Pen Thickness="0.1" Brush="DarkOrange" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<!--竖线-->
<GeometryDrawing Geometry="M1,0 L1,10 M2,0 L2,10 M3,0 L3,10 M4,0 L4,10 M5,0 L5,10 M6,0 L6,10 M7,0 L7,10 M8,0 L8,10 M9,0 L9,10">
<GeometryDrawing.Pen>
<Pen Thickness="0.1" Brush="#CCCCFF" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<!-- 竖线100整数倍 -->
<GeometryDrawing Geometry="M0,0 L0,10">
<GeometryDrawing.Pen>
<Pen Thickness="0.1" Brush="DarkOrange" />
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
<!-- 这里是外框线 -->
<Style x:Key="MyGridBorderStyle">
<Setter Property="Border.Background" Value="{StaticResource MyGridBrushResource}"/>
<Setter Property="Border.HorizontalAlignment" Value="Center"/>
<Setter Property="Border.VerticalAlignment" Value="Top"/>
<Setter Property="Border.BorderBrush" Value="Black"/>
<Setter Property="Border.BorderThickness" Value="1"/>
</Style>
</Canvas.Resources> <!-- 引用方式 -->
<Border Style="{StaticResource MyGridBorderStyle}">
<Canvas Width="700" Height="600">
<!-- // 演示平移 -->
<Canvas Width="800" Height="100" Canvas.Top="0" Canvas.Left="0">
<!-- 不平移-->
<Canvas Width="120" Height="120" Canvas.Left="0" Canvas.Top="0">
<Rectangle Width="80" Height="80" Stroke="Black" />
</Canvas>
<!--水平平移10 -->
<Canvas Width="120" Height="120" Canvas.Left="100" Canvas.Top="0">
<Rectangle Width="80" Height="80" Stroke="Black" />
<Rectangle Width="80" Height="80" Stroke="Red">
<Rectangle.RenderTransform>
<TranslateTransform X="10" />
</Rectangle.RenderTransform>
</Rectangle>
</Canvas><!--垂直平移10 -->
<Canvas Width="120" Height="120" Canvas.Left="200" Canvas.Top="0">
<Rectangle Width="80" Height="80" Stroke="Black" />
<Rectangle Width="80" Height="80" Stroke="Red">
<Rectangle.RenderTransform>
<TranslateTransform Y="10" />
</Rectangle.RenderTransform>
</Rectangle>
</Canvas><!--水平平移10,垂直平移10 -->
<Canvas Width="120" Height="120" Canvas.Left="300" Canvas.Top="0">
<Rectangle Width="80" Height="80" Stroke="Black" />
<Rectangle Width="80" Height="80" Stroke="Red">
<Rectangle.RenderTransform>
<TranslateTransform X="10" Y="10" />
</Rectangle.RenderTransform>
</Rectangle></Canvas>
</Canvas><!-- // 演示缩放 -->
<Canvas Width="800" Height="100" Canvas.Top="100" Canvas.Left="0">
<!-- 未缩放时的原始大小-->
<Canvas Width="120" Height="120" Canvas.Left="0" Canvas.Top="0">
<Rectangle Width="80" Height="80" Stroke="Black" />
</Canvas>
<!--水平缩放比例:2倍 -->
<Canvas Width="120" Height="120" Canvas.Left="100" Canvas.Top="0">
<Rectangle Width="80" Height="80" Stroke="Red">
<Rectangle.RenderTransform>
<ScaleTransform ScaleX="2" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Width="80" Height="80" Stroke="Black" />
</Canvas><!--垂直缩放比例2.5倍 -->
<Canvas Width="120" Height="120" Canvas.Left="300" Canvas.Top="0">
<Rectangle Width="80" Height="80" Stroke="Red">
<Rectangle.RenderTransform>
<ScaleTransform ScaleY="2.5" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Width="80" Height="80" Stroke="Black" />
</Canvas><!--水平、垂直同时缩放2.5倍 -->
<Canvas Width="120" Height="120" Canvas.Left="400" Canvas.Top="0">
<Rectangle Width="80" Height="80" Stroke="Red">
<Rectangle.RenderTransform>
<ScaleTransform ScaleX="2.5" ScaleY="2.5" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Width="80" Height="80" Stroke="Black" />
</Canvas>
</Canvas><!-- // 演示旋转 -->
<Canvas Width="800" Height="100" Canvas.Top="300" Canvas.Left="0">
<!-- 不旋转-->
<Canvas Width="120" Height="120" Canvas.Left="0" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black" />
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--旋转15度(默认以左上角为旋转中心 -->
<Canvas Width="120" Height="120" Canvas.Left="100" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<RotateTransform Angle="15" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="-2" Canvas.Left="-2" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--旋转15度,以右上角为旋转中心 -->
<Canvas Width="120" Height="120" Canvas.Left="200" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<RotateTransform Angle="15" CenterX="80" CenterY="0" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="-2" Canvas.Left="78" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--旋转15度,以左下角为旋转中心 -->
<Canvas Width="120" Height="120" Canvas.Left="300" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<RotateTransform Angle="15" CenterX="0" CenterY="80" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="78" Canvas.Left="-2" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--旋转15度,以右下角为旋转中心 -->
<Canvas Width="120" Height="120" Canvas.Left="400" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<RotateTransform Angle="15" CenterX="80" CenterY="80" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="78" Canvas.Left="78" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--旋转15度,以正方形的中心点为旋转中心 -->
<Canvas Width="120" Height="120" Canvas.Left="500" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<RotateTransform Angle="15" CenterX="40" CenterY="40" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="38" Canvas.Left="38" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
</Canvas><!-- // 演示倾斜 -->
<Canvas Width="800" Height="100" Canvas.Top="400" Canvas.Left="0">
<!-- 原始图形-->
<Canvas Width="120" Height="120" Canvas.Left="0" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black" />
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--沿X轴方向倾斜10度(默认以左上角为原点) -->
<Canvas Width="120" Height="120" Canvas.Left="100" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<SkewTransform AngleX="10" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 倾斜中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="-2" Canvas.Left="-2" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--沿Y轴方向倾斜10度(默认以左上角为原点) -->
<Canvas Width="120" Height="120" Canvas.Left="200" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<SkewTransform AngleY="10" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="-2" Canvas.Left="-2" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--X轴、Y轴同时倾斜10度(默认以左上角为原点) -->
<Canvas Width="120" Height="120" Canvas.Left="300" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<SkewTransform AngleX="10" AngleY="10" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="-2" Canvas.Left="-2" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--设定倾斜中心为矩形的正中心位置,沿X轴倾斜10度 -->
<Canvas Width="120" Height="120" Canvas.Left="400" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<SkewTransform AngleX="10" CenterX="40" CenterY="40" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="38" Canvas.Left="38" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--仍将正方形的中心点作为倾斜中心点,X轴倾斜负10度 -->
<Canvas Width="120" Height="120" Canvas.Left="500" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<SkewTransform AngleX="-10" CenterX="40" CenterY="40" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="38" Canvas.Left="38" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
<!--X轴、Y轴同时倾斜负10度(默认以左上角为原点) -->
<Canvas Width="120" Height="120" Canvas.Left="600" Canvas.Top="20">
<Rectangle Width="80" Height="80" Stroke="Black">
<Rectangle.RenderTransform>
<SkewTransform AngleX="-10" AngleY="-10" />
</Rectangle.RenderTransform>
</Rectangle>
<!-- 旋转中心点 -->
<Ellipse Width="4" Height="4" Fill="Red" Canvas.Top="-2" Canvas.Left="-2" />
<!-- 矩形中心点 -->
<Ellipse Width="4" Height="4" Stroke="Black" Canvas.Top="38" Canvas.Left="38" />
</Canvas>
</Canvas> </Canvas>
</Border></Canvas>

标签:Silverlight,演示,缩放,XAML,从略,winfx,图形,WPF
From: https://blog.51cto.com/JohnsonJu/6090440

相关文章

  • WPF,SilverLight中直线的样式示例
    XAML代码://LineStyle.xaml<ViewboxWidth="600"Height="500"xmlns="​​​http://schemas.microsoft.com/winfx/2006/xaml/presentation​​​"xmlns:x="​​​http:......
  • WPF公章制作之2
    早前,我曾写过一篇:“在WPF中制作正圆形公章”。有空再次研究,使用C#将此WPF程序写了出来。运行效果图:关键C#代码://OfficialSeal.csusingSystem;usingSystem.Windows;usin......
  • WPF中的Frozen(冻结)与线程及其他相关问题
    System.Windows.Freezable类(在WindowsBase.dll中)定义一个对象,该对象具有可修改状态和只读(冻结)状态。派生自Freezable的类提供详细的更改通知,可以是不可变的,并且可以进行......
  • 关于.Net中的计时器及WPF中最适合的计时器问题
    .Net中,至少可以找出5个计时器类型:(1)System.Threading.Timer(2)System.Timers.Timer(3)System.Windows.Forms.Timer(4)System.Web.UI.Timer(5)System.Windows.Threading.Dis......
  • WPF 精修篇 拖拽 DragDrop
    WPF实现拖拽效果<Grid><Grid.ColumnDefinitions><ColumnDefinitionWidth="197*"/><ColumnDefinitionWidth="209*"/><Colum......
  • WPF 精修篇 依赖属性
    依赖属性使用场景1.希望可在样式中设置属性。2.希望属性支持数据绑定。3.希望可使用动态资源引用设置属性。4.希望从元素树中的父元素自动继承属性值。5.希望属性可进......
  • WPF下字体模糊的问题
    一直以来,发现WPF中的小字体下的文字变得比较模糊,比如:WPF与Winform字体显示比较:为了看到更清楚,我们放大点显示: 放得更大些:中文、日文等亚洲文字的显示也存在着类似的问题:在......
  • WPF中的文字修饰——上划线,中划线,基线与下划线
    我们知道,文字的修饰包括:空心字、立体字、划线字、阴影字、加粗、倾斜等。这里只说划线字的修饰方式,按划线的位置,我们可将之分为:上划线、中划线、基线与下划线。如图:从上至下......
  • 给WPF文字加多条修饰线
    这是上篇​​WPF中的文字修饰——上划线,中划线,基线与下划线​​效果图:XAML代码:<Pagexmlns="​​http://schemas.microsoft.com/winfx/2006/xaml/presentation​​​"xmlns......
  • WPF应用程序顶级标签一定是Window吗?
    WPF应用程序顶级标签一定是Window吗? 很多人误以为是。可是,答案却是否定的。我们不妨来测试一下。首先使用顶级标签为Window,这是最普通、也是最常见的情况。新建一个WPF应......