当前位置:编程学习 > asp >>

WPF中绘画和动画(4)

接下来我们看一个VisualBrush的例子。为了简单起见,目标控件是一个Button,实际工作中换成复杂控件的效果也一样。程序的XAML代码如下:

<Window x:Class="WpfApplication1.Window2"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="VisualBrush" Height="300" Width="400"Background="Orange">

    <Grid Margin="10">

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="160"/>

            <ColumnDefinition Width="*"/>

            <ColumnDefinition Width="160"/>

        </Grid.ColumnDefinitions>      

        <StackPanel x:Name="stackPanelLeft" Background="White">

            <Button x:Name="realButton" Content="OK" Height="40"/>

        </StackPanel>      

        <Button Content=">>>" Grid.Column="1" Margin="5,0" Click="Button_Click" />      

        <StackPanel x:Name="stackPanelRight" Background="White" Grid.Column="2"/>

    </Grid>

</Window>

中间Button的Click事件处理器代码如下:

doubleo=1.0; //不透明度计数器

 

        privatevoidButton_Click(objectsender, RoutedEventArgse)

        {

            VisualBrushvBrush=newVisualBrush(this.realButton);

            Rectanglerect=newRectangle();

            rect.Width=realButton.ActualWidth;

            rect.Height=realButton.ActualHeight;

            rect.Fill=vBrush;

            rect.Opacity=o;

            o-=0.2;

 

            this.stackPanelRight.Children.Add(rect);

        }

 

摘自 wangganggang90的专栏

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,