日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > asp.net >内容正文

asp.net

WPF 右下角弹窗的简单实现

發(fā)布時(shí)間:2023/12/4 asp.net 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF 右下角弹窗的简单实现 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

軟件中經(jīng)常出現(xiàn)右下角彈窗,從下面緩緩彈出的,這次就做個(gè)簡(jiǎn)陋的實(shí)現(xiàn),

思路就是在窗口加載和關(guān)閉時(shí)執(zhí)行動(dòng)畫(huà)DoubleAnimation

今天懶得做界面了,只實(shí)現(xiàn)了功能。

看看效果:

下面看看代碼:

主窗口添加一個(gè)按鈕 ,點(diǎn)擊事件:

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

,新建一個(gè)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="關(guān)閉" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5" Click="Button_Click"/><TextBlock Text="{Binding Message,ElementName=window}" FontSize="35" HorizontalAlignment="Center" VerticalAlignment="Center"/></Grid> </Window>

后臺(tái)代碼:

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);}} }

完啦?

總結(jié)

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

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。