WPF之实现NotifyBox(弹窗信息)

WPF之实现NotifyBox

在这里插入图片描述

Name="ThisWindow"
WindowStyle="None"
ResizeMode="NoResize"
AllowsTransparency="True"
Background="Transparent"
Title="NotifyBox" Height="80" Width="380" Loaded="ThisWindow_Loaded"

在这里插入图片描述
在这里插入图片描述

动画

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/ModuleView;component/SummaryStyle.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <!--展开的动画-->
            <Storyboard x:Key="OpenStoryboard" Completed="Storyboard_Completed">
                <DoubleAnimation 
                From="0" To="{Binding ElementName=ThisWindow,Path=Width}" 
                Duration="00:00:00.5"
                Storyboard.TargetName="RootBorder" Storyboard.TargetProperty="Width">
                    <DoubleAnimation.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </DoubleAnimation.EasingFunction>
                </DoubleAnimation>
            </Storyboard>
            <!--收缩的动画-->
            <Storyboard x:Key="CloseStoryboard" Completed="Storyboard_Completed_1">
                <DoubleAnimation 
                From="{Binding ElementName=ThisWindow,Path=Width}" To="0" 
                Duration="00:00:00.3"
                Storyboard.TargetName="RootBorder" Storyboard.TargetProperty="Width">
                    <DoubleAnimation.EasingFunction>
                        <CubicEase EasingMode="EaseOut"/>
                    </DoubleAnimation.EasingFunction>
                </DoubleAnimation>
            </Storyboard>
        </ResourceDictionary>
    </Window.Resources>

触发器

    <Window.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <BeginStoryboard>
                <StaticResource ResourceKey="OpenStoryboard"/>
            </BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>

边框样式

    <Border HorizontalAlignment="Right" Name="RootBorder" Style="{StaticResource borderStyle}">
        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" FontSize="14" Name="MessageBox" TextWrapping="Wrap"/>
    </Border>

显示文本事件

     public string NotifyMessage { get; set; }

     private void ThisWindow_Loaded(object sender, RoutedEventArgs e)
     {
         MessageBox.Text = NotifyMessage;
     }

在这里插入图片描述

显示位置右下角,展开和收缩动画事件

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.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ModuleView._04NotifyBox
{
    /// <summary>
    /// NotifyBox.xaml 的交互逻辑
    /// </summary>
    public partial class NotifyBox : Window
    {
        public NotifyBox()
        {
            InitializeComponent();
            // 显示位置(右下角)
            Left = SystemParameters.WorkArea.Width - Width;
            Top = SystemParameters.WorkArea.Height - Height - 25;
        }

        /// <summary>
        /// 展开的动画
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async private void Storyboard_Completed(object sender, EventArgs e)
        {
            await Task.Delay(1500);
            BeginStoryboard(FindResource("CloseStoryboard") as Storyboard);
        }

        /// <summary>
        /// 收缩的动画
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Storyboard_Completed_1(object sender, EventArgs e)
        {
            Close();
            //Hide();
        }

        /// <summary>
        /// 提示消息
        /// </summary>
        public string NotifyMessage { get; set; }

        private void ThisWindow_Loaded(object sender, RoutedEventArgs e)
        {
            MessageBox.Text = NotifyMessage;
        }


    }
}

使用

  //消息提示窗体
  NotifyBox notify = new NotifyBox() { NotifyMessage = "创建解决方案" };
  notify.ShowInTaskbar = false;
  notify.Show();

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值