본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

WPF & C# - toastMessage 처럼 보이기 ( 토스트메세지 / 토스트메시지 / ToastMsg )

728x90
반응형


 WPF & C# - toastMessage 처럼 보이기 ( 토스트메세지 / 토스트메시지 / ToastMsg / 새창 )





@ MainWindow.xaml.cs


1
2
3
4
5
6
7
8
9
10
 
        // ToastMessage 토스트메세지 활용하기
        private void ToastMessage(string TM_Msg, string TM_Icon)
        {
            Application.Current.Properties["TM_Msg"= TM_Msg;
            Application.Current.Properties["TM_Icon"= TM_Icon;
 
            Window Splash_Message = new Splash_Message();
            Splash_Message.Show();
        }
cs




@ ToastMessage.xaml


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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">
    <Grid>
        <Rectangle x:Name="Rectangle1" Fill="#FFE3EAE7" Margin="10" Stroke="Black" RadiusX="20" RadiusY="20" Height="50"/>
        <TextBlock x:Name="TB_Msg" Margin="10"  FontSize="16" HorizontalAlignment="Center" VerticalAlignment="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
public ToastMessage()
{
    InitializeComponent();
 
    this.AllowsTransparency = true;
    this.Topmost = true;
 
    if (Application.Current.Properties["TM_Msg"!= null)
    {
        TB_Msg.Text = Application.Current.Properties["TM_Msg"].ToString();
    }
 
    this.Visibility = Visibility.Visible;
    DoubleAnimation dba1 = new DoubleAnimation();
    dba1.From = 0;
    dba1.To = 3;
    dba1.Duration = new Duration(TimeSpan.FromSeconds(0.8));
    dba1.AutoReverse = true;
    // 애니메이션 종료 이벤트 ( ※ BeginAnimation 이전에 있어야 동작함)
    dba1.Completed += (s, a) =>
    {
        Close();
    };
    this.BeginAnimation(OpacityProperty, dba1);
}
cs



 @ toastMessage 처럼 보이기???

제목을 이렇게 지은 이유가 있다.

실제 고수들이 사용하는 그런 방식보다 허접하다는걸 스스로 알아서다.

다만, 실력이 부족해도 내가 당장 할 수 있는 방법으로나마 해보고 싶었다.

Android 의 메세지는 거슬리지 않으면서 간결할고 깔끔하게 보여준다는 느낌이 있었기 때문이다.

어쨌든 처음 해보는거 치고는 성공적인듯하다.

하나하나 만들어 가는 재미가 쏠쏠 하다. ^^


혹시 창 닫히는 부분 좀 더 효율적으로 아시면 좀 알려주세요~ ^^





http://insurang.tistory.com


728x90
반응형