日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

WPF 右下角弹窗的简单实现

發布時間:2023/12/4 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF 右下角弹窗的简单实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

軟件中經常出現右下角彈窗,從下面緩緩彈出的,這次就做個簡陋的實現,

思路就是在窗口加載和關閉時執行動畫DoubleAnimation

今天懶得做界面了,只實現了功能。

看看效果:

下面看看代碼:

主窗口添加一個按鈕 ,點擊事件:

private void Button_Click(object sender, RoutedEventArgs e){NotifyWindow notifyWindow = new NotifyWindow() { Message="MessageBox" };notifyWindow.Show();}

,新建一個NotifyWindow:

xaml:

<Window x:Class="WPFDemos.NotifyWindow"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:WPFDemos"mc:Ignorable="d"Background="Transparent"AllowsTransparency="True"WindowStyle="None"x:Name="window"Title="NotifyWindow" Height="200" Width="300"><Grid Margin="8" Background="White"><Grid.Effect><DropShadowEffect BlurRadius="8" ShadowDepth="0" Color="Black"/></Grid.Effect><Button Content="關閉" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5" Click="Button_Click"/><TextBlock Text="{Binding Message,ElementName=window}" FontSize="35" HorizontalAlignment="Center" VerticalAlignment="Center"/></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.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes;namespace WPFDemos {/// <summary>/// NotifyWindow.xaml 的交互邏輯/// </summary>public partial class NotifyWindow : Window{public NotifyWindow(){InitializeComponent();Loaded += NotifyWindow_Loaded;}private void NotifyWindow_Loaded(object sender, RoutedEventArgs e){Left = SystemParameters.WorkArea.Right - this.Width;Top = SystemParameters.WorkArea.Bottom;var animation = new DoubleAnimation{Duration = new Duration(TimeSpan.FromSeconds(0.5)),To = SystemParameters.WorkArea.Bottom - this.Height,};this.BeginAnimation(TopProperty, animation);}private string message = "Message";public string Message{get { return message; }set { message = value; }}private void Button_Click(object sender, RoutedEventArgs e){var animation = new DoubleAnimation{Duration = new Duration(TimeSpan.FromSeconds(0.3)),To = SystemParameters.WorkArea.Bottom,};animation.Completed += (ss, ee) =>{this.Close();};this.BeginAnimation(TopProperty,?animation);}} }

完啦?

總結

以上是生活随笔為你收集整理的WPF 右下角弹窗的简单实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。