您好,欢迎来到飒榕旅游知识分享网。
搜索
您的当前位置:首页wpf VisualBrush的使用

wpf VisualBrush的使用

来源:飒榕旅游知识分享网
<Window x:Class="WpfApp04.TestWin08"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp04"
        mc:Ignorable="d"
        Title="TestWin08" Height="450" Width="800">
    <Grid Margin="10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="160"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
            <ColumnDefinition Width="160"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <StackPanel x:Name="spLeft" Background="White">
            <Button x:Name="realButton" Content="OK" Height="40"/>
        </StackPanel>
        <Button Content=">>" Grid.Column="1" Margin="5,0" Click="CloneVisual"/>
        <StackPanel x:Name="spRight" Background="White" Grid.Column="2"/>
    </Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApp04
{
    /// <summary>
    /// TestWin08.xaml 的交互逻辑
    /// </summary>
    public partial class TestWin08 : Window
    {
        public TestWin08()
        {
            InitializeComponent();
        }

        double opacity= 1.0;
        private void CloneVisual(object sender, RoutedEventArgs e)
        {
            VisualBrush brush = new VisualBrush(this.realButton);
            Rectangle rect = new Rectangle();
            rect.Width = realButton.ActualWidth;
            rect.Height = realButton.ActualHeight;
            rect.Fill = brush;
            rect.Opacity = opacity;
            opacity -= 0.2;

            this.spRight.Children.Add(rect);
        }
    }
}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- sarr.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务