变换类:
TranslateTransform ——将坐标系统移动一定的距离,在不同的地方绘制相同的对象
RotateTransform—— 旋转变换
ScaleTransform ——放大缩小坐标系统
SkewTransform ——通过倾斜一定的角度,扭曲坐标系统(正方形----> 平行四边形)
<Canvas> <Rectangle Width="80" Height="10" Stroke="Blue" Fill="Yellow" Canvas.Left="100" Canvas.Top="100"/> <!--使用绝对坐标 CenterX、Y--> <Rectangle Width="80" Height="10" Stroke="Blue" Fill="Yellow" Canvas.Left="100" Canvas.Top="100"> <Rectangle.RenderTransform> <RotateTransform Angle="25" CenterX="40" CenterY="5"></RotateTransform> </Rectangle.RenderTransform> </Rectangle> <!--使用相对坐标 RenderTransformOrigin--> <Rectangle Width="80" Height="10" Stroke="Blue" Fill="Yellow" Canvas.Left="100" Canvas.Top="100" RenderTransformOrigin="0.5,0.5"> <Rectangle.RenderTransform> <RotateTransform Angle="50"></RotateTransform> </Rectangle.RenderTransform> </Rectangle> </Canvas>
RenderTransform (先布局再旋转)与LayoutTransform (先旋转再布局)
<StackPanel Margin="5" Background="LightYellow"> <StackPanel Margin="25" Background="AliceBlue"> <Button Padding="5" HorizontalAlignment="Left" Content="I'm ratated 35 degrees"> <Button.RenderTransform > <!--<Button.RenderTransform 先布局再旋转>--> <RotateTransform Angle="35" CenterX="35" CenterY="5"></RotateTransform> </Button.RenderTransform> </Button> <Button Padding="5" HorizontalAlignment="Left" Content="I'm not"/> </StackPanel> <StackPanel Margin="25" Background="AliceBlue"> <Button Padding="5" HorizontalAlignment="Left" Content="I'm ratated 35 degrees"> <Button.LayoutTransform > <!--<Button.LayoutTransform 先旋转再布局>--> <RotateTransform Angle="35" CenterX="35" CenterY="5"></RotateTransform> </Button.LayoutTransform> </Button> <Button Padding="5" HorizontalAlignment="Left" Content="I'm not"/> </StackPanel> </StackPanel>
透明:
- Opacity="0.4"
- Background="#A0FF0000" 前两个字符表示 透明度,FF 表示完全不透明
<StackPanel Margin="25" Background="#A0FF0000" > <!--前两个字符表示 透明度,FF 表示完全不透明--> <!--<StackPanel.Background> <ImageBrush ImageSource="/Demo.WPFLearning;component/Assets/SplashScreen/photo.jpeg" Opacity="0.4"/> </StackPanel.Background>--> </StackPanel>
透明掩码: (映射不了??)
<Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <TextBox Name="txt" FontSize="30" >Here is some reflected text</TextBox> <Rectangle Grid.Row="1" RenderTransformOrigin="1,0.5" > <Rectangle.Fill> <VisualBrush Visual="{Binding ElementName=txt}"></VisualBrush> </Rectangle.Fill> <Rectangle.OpacityMask> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0.3" Color="Transparent"/> <GradientStop Offset="1" Color="DarkViolet"/> </LinearGradientBrush> </Rectangle.OpacityMask> <Rectangle.RenderTransform> <ScaleTransform ScaleY="-1"></ScaleTransform> </Rectangle.RenderTransform> </Rectangle> </Grid>