wpf 右下角弹出窗

news/2024/8/26 17:33:34
wpf 右下角弹出窗
原文: 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();
        }
    }
}

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

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

posted on 2019-03-05 22:41 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/10480345.html


http://www.niftyadmin.cn/n/929223.html

相关文章

第八次作业(课堂实战)- 项目UML设计(团队)

1. 团队信息 队名&#xff1a;小白吃队成员&#xff1a; 后敬甲 031602409卢泽明 031602328蔡文斌 031602301葛亮 031602617刘浩 031602423黄泽 031602317黄婧茹 031602315组长&#xff1a;后敬甲2.团队分工 WBS Alpha版本 任务槽 登陆注册界面完成自选窗口的识别结算功能实现学…

php审计--灰盒角度来复现经典反序列化

站在巨人的肩膀上做反序列化复现&#xff0c;&#xff0c; 这里已经找了fwrite()函数和read()函数&#xff0c;file_get_contents($file);都不能代替fopen()函数做复现&#xff0c;&#xff0c;本人水平有限&#xff0c;希望读者不要介意&#xff0c; 我们从灰盒的角度做学习…

App Store评论优化,让你的APP评论上涨

App Store评论优化怎么做 App Store评论优化&#xff0c;让你的APP评论上涨 关于「ASO评论优化」&#xff0c;主要分为三块。换评论&#xff0c;买评论&#xff0c;引导用户写评论。 可能有些刚接触ASO的朋友会问&#xff0c;为什么要给APP做评论呢?ASO优化师的工作不是主要做…

使用 fetch 封装网络请求,返回promise 对象

1.fetch 的概念和用法 fetch 提供了对 Request 和 Response &#xff08;以及其他与网络请求有关的&#xff09;对象的通用定义。使之今后可以被使用到更多地应用场景中&#xff1a;无论是service workers、Cache API、又或者是其他处理请求和响应的方式&#xff0c;甚至是任何…

php审计--通过php伪协议配合文件包含写入shell

有群友问过这样一个问题&#xff0c;&#xff0c; http:xxx/123.jpg 传上这样的图片马能不能连到shell&#xff1f; 这有几种情况&#xff0c;&#xff0c;&#xff0c;php解析吧jpg解析成php&#xff0c;iis吧jpg解析成php都可以 我们这里通过php伪协议存在文件包含的页面做个…

列表推导式、生成器表达式

列表推导式 egg ["鸡蛋{}".format(i) for i in range(1, 11)]print(egg)生成器表达式 eggs ("鸡蛋{}".format(i) for i in range(1, 11))for egg in eggs: print(egg)二者的括号不一样&#xff0c;前者是中括号&#xff0c;且返回整个列表&#xff0c…

jenkins active choice parameter插件

actice choice 这个插件的作用是可以在参数化构建时&#xff0c;创建一个可选的参数例如&#xff0c;用jenkins创建一个发布project时&#xff0c;我们发布过程中需要选择环境、服务名称等&#xff0c;我们希望在参数化构建时&#xff0c;可以提供一个下拉框给用户进行选择&…

yxcms1.4.7版本审计sql注入-文件删除盲注配合dnslog解析数据

这是一篇cms审计内容&#xff0c;和之前做的文件包含伪协议、反序列化入门内容不同&#xff0c;&#xff0c;拿项目练手。 我找了一下网上关于yxcms的漏洞&#xff0c;谷歌收录到1.4.6存在前台注入和后台文件删除盲注这两个洞&#xff0c;&#xff0c;对比发现1,4,7版本源码几乎…