• wpf 右下角弹出窗


    自己写的wpf 弹出框,欢迎拍砖,动画都写在了后台代码,前台代码不太重要,用了一下iconfont,具体样式我就不贴出来了,本次主要是后台代码的动画

    需要有父级窗口才可以使用。

    前台代码:

    <Window x:Class="V2VReporter.Views.SystemViews.MsgPopup"
            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:V2VReporter.Views.SystemViews"
            xmlns:controls="clr-namespace:V2VReporter.Controls"
            mc:Ignorable="d"
            Title="系统消息" Height="230" Width="300" AllowsTransparency="True" WindowStyle="None" ShowInTaskbar="False">
        <Border BorderBrush="{StaticResource SideLevel1}" BorderThickness="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Background="{StaticResource MainGreen}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <StackPanel Grid.Column="0" Orientation="Horizontal">
                        <TextBlock Text="&#xeb66;" Style="{StaticResource IconFont}" VerticalAlignment="Center" FontSize="18" Foreground="AliceBlue" Margin="5,0,0,0"></TextBlock>
                        <TextBlock Text="系统消息" Foreground="AliceBlue" FontSize="15" VerticalAlignment="Center" Margin="2,0,0,0" ></TextBlock>
                    </StackPanel>
                    <StackPanel Grid.Column="1" HorizontalAlignment="Right">
                        <controls:IconButton Style="{StaticResource TitleCloseBtn}" Margin="0,5,2,0" Click="ButtonBase_OnClick"></controls:IconButton>
                    </StackPanel>
                </Grid>
            </Grid>
        </Border>
    </Window>

    后台代码:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    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.Animation;
    using System.Windows.Media.Imaging;
    using System.Windows.Shapes;
    using V2VReporter.Resource;
    
    namespace V2VReporter.Views.SystemViews
    {
        /// <summary>
        /// MsgPopup.xaml 的交互逻辑
        /// </summary>
        public partial class MsgPopup:Window
        {
            /// <summary>
            /// 关闭动画
            /// </summary>
            private Storyboard sb_close=new Storyboard();
            /// <summary>
            /// 关闭标识
            /// </summary>
            private bool close_flg = false;
            /// <summary>
            /// 关闭动画
            /// </summary>
            private DoubleAnimation close=new DoubleAnimation();
            /// <summary>
            /// 窗口弹出
            /// </summary>
            private Storyboard sb_loaded=new Storyboard();
            /// <summary>
            /// 窗口弹出动画
            /// </summary>
            private DoubleAnimation load=new DoubleAnimation();
            /// <summary>
            /// 窗口加载动画
            /// </summary>
            private DoubleAnimation loadOp=new DoubleAnimation();
    
    
            public MsgPopup(Window win)
            {
                InitializeComponent();
    
                initedCloseStory();
                initedLoadStory(win);
                sb_loaded.Begin();
            }
    
            private void initedLoadStory(Window win)
            {
                this.Owner = win;
                this.Left = win.Width - this.Width;
                load.From = win.Height;
                load.To = win.Height - this.Height;
                load.Duration = new Duration(TimeSpan.FromSeconds(1.5));
                load.FillBehavior = FillBehavior.HoldEnd;
                load.AutoReverse = false;
                sb_loaded.Children.Add(load);
                Storyboard.SetTarget(load, this);
                Storyboard.SetTargetProperty(load, new PropertyPath("Top"));
    
                loadOp.From = 0;
                loadOp.To = 1;
                loadOp.Duration=new Duration(TimeSpan.FromSeconds(1.5));
                loadOp.FillBehavior = FillBehavior.HoldEnd;
                loadOp.AutoReverse = false;
                sb_loaded.Children.Add(loadOp);
                Storyboard.SetTarget(loadOp, this);
                Storyboard.SetTargetProperty(loadOp, new PropertyPath("Opacity"));
    
            }
    
            private void initedCloseStory()
            {
                close.From = 1;
                close.To = 0;
                close.Duration = new Duration(TimeSpan.FromSeconds(1));
                close.FillBehavior = FillBehavior.HoldEnd;
                close.AutoReverse = false;
                sb_close.Children.Add(close);
                Storyboard.SetTarget(close, this);
                Storyboard.SetTargetProperty(close, new PropertyPath("Opacity"));
            }
    
            protected override void OnClosing(CancelEventArgs e)
            {
                base.OnClosing(e);
                if (!close_flg)
                {
                    sb_close.Completed += delegate
                    {
                        close_flg = true;
                        this.Close();
                    };
                    sb_close.Begin();
                    e.Cancel = true;
                }
                else
                {
                    e.Cancel = false;
                }
            }
    
            private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
            {
                this.Close();
            }
        }
    }

    直接用的话会运行不起来,主要看后台动画代码和逻辑

    本文属原创 转载请写明出处

  • 相关阅读:
    树的基本概念
    bean的生命周期
    bean的创建过程--doCreateBean
    bean的创建过程--doGetBean
    SpringBoot自动装配解析
    [论文理解] Good Semi-supervised Learning That Requires a Bad GAN
    Ubuntu 环境安装 opencv 3.2 步骤和问题记录
    Linux 环境使用 lsof 命令查询端口占用
    Ubuntu 安装不同版本的 gcc/g++ 编译器
    [持续更新] 安全能力成长计划
  • 原文地址:https://www.cnblogs.com/wuyaxiansheng/p/10103839.html
Copyright © 2020-2023  润新知