自学WPF--第六课VisualBrush

 

VisualBrush画刷是一种特殊的画刷,他通过将一定区域映射为某一空间的外观。

重要属性:Visual:设置映射源。

实例练习如下:

 

<Grid>

        <TextBox Height="44" HorizontalAlignment="Left" Margin="112,75,0,0" Name="textBox1" VerticalAlignment="Top" Width="250" FontSize="16" />

        <Rectangle Height="45" HorizontalAlignment="Left" Margin="112,148,0,0" Name="rectangle1" Stroke="Black" StrokeThickness="0" VerticalAlignment="Top" Width="250" >

            <Rectangle.Fill>

                <VisualBrush Visual="{Binding ElementName=textBox1}">

                    <VisualBrush.RelativeTransform>

                        <TransformGroup>

                            <ScaleTransform ScaleX="1" ScaleY="-1"/>

                            <TranslateTransform Y="1"/>

                        </TransformGroup>

                    </VisualBrush.RelativeTransform>

                </VisualBrush>

            </Rectangle.Fill>

        </Rectangle>

    </Grid>

Visual=”{Binding ElementName=textBox1}”:指将textBox1作为映射源.

VisualBrush.RelativeTransform:指对图像进行相对变换。

ScaleTransform:指对图像进行缩放。ScaleX沿X轴进行变换,ScaleY沿Y轴进行变化。

如果ScaleX的值介于0-1则对图像进行缩小变化,大于1则对对象进行放大。负数指对图像进行缩放并翻转,0-(-1)指对图像进行缩小并翻转.

Y表示对图像沿Y轴移动的距离,默认值为0。正值表示向下移动对象,负值表示向上移动对象。

TranslateTransform:对图像进行位置偏移,Y:相对Y轴的偏移量。

由于ScaleTransform和TranslateTransform都是对图像进行转换,所以将它们放在一个TransformGroup内。

练习2如下:

<Grid Height="317" Width="515">

    

    <Grid.Background>

            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">

                <GradientStop Color="Black" Offset="0"/>

                <GradientStop Color="White" Offset="1"/>

            </LinearGradientBrush>

        </Grid.Background>

        <TextBox Height="55" HorizontalAlignment="Left" Margin="70,21,0,0" Name="textBox1" VerticalAlignment="Top" Width="345" FontSize="20" FontStyle="Normal" FontWeight="Bold">

            <TextBox.Background>

                <ImageBrush ImageSource="images/1.jpg"/>

            </TextBox.Background>

        </TextBox>

        <Rectangle Height="110" HorizontalAlignment="Left" Margin="70,82,0,0" Name="rectangle1" Stroke="Black" StrokeThickness="0"  VerticalAlignment="Top" Width="345" >

            <Rectangle.Fill>

                <VisualBrush  Visual="{Binding ElementName=textBox1}">

                    <VisualBrush.RelativeTransform>

                        <TransformGroup>

                             <ScaleTransform  ScaleX="1" ScaleY="-1"/>

                             <TranslateTransform Y="1"/>

                        </TransformGroup>                     

                     

                    </VisualBrush.RelativeTransform>

                </VisualBrush>

            </Rectangle.Fill>

        </Rectangle>      

    </Grid>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值