先看效果:
新建一个WPF窗体UMessageBox:
xaml代码:
后台代码:
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.Imaging;
using System.Windows.Shapes;
namespace WPF20201123.Views
{
///
/// UMessageBox.xaml 的交互逻辑
///
public partial class UMessageBox : Window
{
public UMessageBox()
{
InitializeComponent();
}
public new string Title
{
get { return this.lblTitle.Text; }
set { this.lblTitle.Text = value; }
}
public string Message
{
get { return this.lblMsg.Text; }
set { this.lblMsg.Text = value; }
}
///
/// 静态方法 模拟MESSAGEBOX.Show方法
///
/// 标题
/// 消息
///
public static bool? Show(string title, string msg)
{
var msgBox = new UMessageBox();
msgBox.Title = title;
msgBox.Message = msg;
return msgBox.ShowDialog();
}
//private void Yes_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
//{
// this.DialogResult = true;
// this.Close();
//}
//private void No_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
//{
// this.DialogResult = false;
// this.Close();
//}
private void btn_Cancel_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
//this.Close();
}
private void btn_OK_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
//this.Close();
}
private void panel_Title_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ButtonState == MouseButtonState.Pressed)
{
this.DragMove();
}
}
private void btn_Close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
使用方法:
UMessageBox.Show("提示:", "欢迎使用!");
或
bool? result = UMessageBox.Show("提示:", "导出成功!是否用IDE运行?");
if(result == true)
{
//其它
}



