using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Shapes;
namespace WpfNoticeMsg
{
///
/// NoticeMessage.xaml 的交互逻辑
///
public partial class NoticeMessage : Window
{
public NoticeMessage()
{
InitializeComponent();
}
///
/// 显示消息
///
///
///
///
public static void Show(string msg, string title = "提示", int sleep = 2000)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
NoticeMessage noticeMessage = new NoticeMessage();
noticeMessage.Owner = Application.Current.MainWindow;
noticeMessage.txt_Title.Text = title;
noticeMessage.txtMsg.Text = msg;
noticeMessage.Height= noticeMessage.grid.ActualHeight;
noticeMessage.Width = noticeMessage.grid.ActualWidth + 30;
noticeMessage.Show();
Task.Factory.StartNew(() =>
{
Thread.Sleep(sleep);
Application.Current.Dispatcher.Invoke(() =>
{
noticeMessage.Close();
});
});
}));
}
private void close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}