You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.8 KiB
95 lines
2.8 KiB
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
|
|
{
|
|
/// <summary>
|
|
/// NoticeMessage.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class NoticeMessage : Window
|
|
{
|
|
public NoticeMessage()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示消息
|
|
/// </summary>
|
|
/// <param name="msg"></param>
|
|
/// <param name="title"></param>
|
|
/// <param name="sleep"></param>
|
|
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();
|
|
});
|
|
});
|
|
}));
|
|
}
|
|
|
|
|
|
public static void Show(Window window, string msg, string title = "提示", int sleep = 2000)
|
|
{
|
|
window.Dispatcher.BeginInvoke(new Action(() =>
|
|
{
|
|
NoticeMessage noticeMessage = new NoticeMessage();
|
|
try
|
|
{
|
|
noticeMessage.Owner = window;
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
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);
|
|
window.Dispatcher.Invoke(() =>
|
|
{
|
|
noticeMessage.Close();
|
|
});
|
|
});
|
|
}));
|
|
}
|
|
private void close_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|
|
|