WPF 에서 toast 메시지 만들기
안드로이드에는 알림창으로 toast 메시지가 있습니다. 하지만 wpf에서는 윈도우 메시지 같은 형식밖에 없는데요,
Label과 DoubleAnimation을 이용하여 toast 메시지와 비슷한 형식을 만들어 보았습니다.
using System.Windows.Media.Animation;
private void ToastMessage(string message)
{
lblToast.Content = message;
DoubleAnimation dba1 = new DoubleAnimation();
dba1.From = 0;
dba1.To = 1;
dba1.Duration = new Duration(TimeSpan.FromSeconds(1.5));
DoubleAnimation dba2 = new DoubleAnimation();
dba2.From = 1;
dba2.To = 0;
dba2.Duration = new Duration(TimeSpan.FromSeconds(1.5));
dba1.Completed += delegate (object sender1, EventArgs e1)
{
lblToast.BeginAnimation(OpacityProperty, dba2);
};
lblToast.BeginAnimation(OpacityProperty, dba1);
}
dba1이 끝날 경우 dba2 를 실행하게 하여 레이블의 opacity가 1이 된 뒤 다시 0이 되도록 하는 애니메이션입니다.
lblToast를 toast 메시지가 뜨기를 원하는 위치에 두신 후 zindex를 가장 크게 해주시면 됩니다.