728x90
반응형
【 WPF & C# (C Sharp) 】
@ DoubleAnimation을 이용한 ToastMessage 토스트메세지 toast Message
# 활용방법
ToastMessage("시작프로그램 등록", "");
# MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Window ToastMessage_Window = (Window)Application.LoadComponent(new Uri("ToastMessage.xaml", UriKind.Relative)); private void ToastMessage(string TM_Msg, string TM_Icon) { Application.Current.Properties["TM_Msg"] = TM_Msg; Application.Current.Properties["TM_Icon"] = TM_Icon; ToastMessage_Window.Visibility = Visibility.Visible; DoubleAnimation dba1 = new DoubleAnimation(); dba1.Completed += new EventHandler(dba1_Completed); dba1.From = 0; dba1.To = 3; dba1.Duration = new Duration(TimeSpan.FromSeconds(0.8)); dba1.AutoReverse = true; ToastMessage_Window.BeginAnimation(OpacityProperty, dba1); } void dba1_Completed(object sender, EventArgs e)
{
ToastMessage_Window.Visibility = Visibility.Hidden;
} | cs |
# ToastMessage.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <Window x:Name="Splash_Message1" x:Class="WpfApp4.Splash_Message" 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:WpfApp4" mc:Ignorable="d" Title="ToastMessage" Height="80" Width="400" Background="{x:Null}" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" AllowsTransparency="True" WindowStyle="None" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" TouchDown="Splash_Message1_TouchDown" MouseDown="Splash_Message1_MouseDown" LayoutUpdated="Splash_Message1_LayoutUpdated"> <Grid> <Rectangle x:Name="Rectangle1" Fill="#FFE3EAE7" Margin="10" Stroke="Black" RadiusX="20" RadiusY="20"/> <Label x:Name="lbl_Msg" Content="" Margin="10" VerticalContentAlignment="Center" FontSize="16" HorizontalContentAlignment="Center"/> <Image Margin="21,25,0,0" Source="Image1.png" Stretch="Fill" HorizontalAlignment="Left" Width="42" Height="37" VerticalAlignment="Top"/> </Grid> </Window> | cs |
# ToastMessage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 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 WpfApp4 { /// <summary> /// Splash_Message.xaml에 대한 상호 작용 논리 /// </summary> public partial class Splash_Message : Window { public Splash_Message() { InitializeComponent(); AllowsTransparency = true; Topmost = true; } /// <summary> /// 스토리보드 기능 /// </summary> /// <param name="targetname"></param> private void Splash_Message1_TouchDown(object sender, TouchEventArgs e) { DragMove(); } private void Splash_Message1_MouseDown(object sender, MouseButtonEventArgs e) { DragMove(); } private void Splash_Message1_LayoutUpdated(object sender, EventArgs e) { lbl_Msg.Content = Application.Current.Properties["TM_Msg"]; } } } | cs |
728x90
반응형