你的位置:首页 > ASP.net教程

[ASP.net教程]WPF 提示框、确认框、确认输入框


1、弹出的方法

/// <summary>
/// 弹出提示
/// 标题:提示
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowInfoMessageBox( string strContent)
{
AlertRadWindow(Application.Current.MainWindow, strContent, Application.Current.Resources["MessageInfoStyle"] as Style, "提示");
}
/// <summary>
/// 弹出提示
/// 标题:异常
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowExceptionMessageBox(string strContent)
{
AlertRadWindow(Application.Current.MainWindow, strContent, Application.Current.Resources["MessageInfoStyle"] as Style, "异常");
}
/// <summary>
/// 弹出提示
/// 标题:失败
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowErrorMessageBox( string strContent)
{
AlertRadWindow(Application.Current.MainWindow, strContent, Application.Current.Resources["MessageErrorStyle"] as Style, "失败");
}
/// <summary>
/// 弹出提示
/// 标题:成功
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowSuccessMessageBox( string strContent)
{
AlertRadWindow(Application.Current.MainWindow, strContent, Application.Current.Resources["MessageSuccessStyle"] as Style, "成功");
}
/// <summary>
/// 弹出提示
/// 标题:提示
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowInfoMessageBox(ContentControl owner, string strContent)
{
AlertRadWindow(owner, strContent, Application.Current.Resources["MessageInfoStyle"] as Style, "提示");
}
/// <summary>
/// 弹出提示
/// 标题:异常
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowExceptionMessageBox(ContentControl owner, string strContent)
{
AlertRadWindow(owner, strContent, Application.Current.Resources["MessageInfoStyle"] as Style, "异常");
}
/// <summary>
/// 弹出提示
/// 标题:失败
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowErrorMessageBox(ContentControl owner, string strContent)
{
AlertRadWindow(owner, strContent, Application.Current.Resources["MessageErrorStyle"] as Style, "失败");
}
/// <summary>
/// 弹出提示
/// 标题:成功
/// </summary>
/// <param name="strContent">内容</param>
public static void ShowSuccessMessageBox(ContentControl owner, string strContent)
{
AlertRadWindow(owner, strContent, Application.Current.Resources["MessageSuccessStyle"] as Style, "成功");
}
private static void AlertRadWindow(ContentControl owner,string strContent, Style style, string header)
{
RadWindow.Alert(new DialogParameters()
{
Owner = owner,
Content = new TextBlock() { Text = strContent, TextWrapping = TextWrapping.Wrap, VerticalAlignment = VerticalAlignment.Center },
ContentStyle = style,
Header = header,
});
}
/// <summary>
/// 确认对话框
/// 默认以OK,Cancel作为按键
/// </summary>
/// <param name="strContent">内容</param>
/// <param name="onClosed">关闭事件 案例:new EventHandler WindowClosedEventArgs(OnClosed))</param>
public static void ShowConfirmMessageBox(string strContent, EventHandler<WindowClosedEventArgs> onClosed)
{
ShowConfirmMessageBox(strContent, onClosed,"确定","取消");
}
/// <summary>
/// 确认对话框
/// </summary>
/// <param name="strContent">内容</param>
/// <param name="onClosed">关闭事件 案例:new EventHandler WindowClosedEventArgs(OnClosed))</param>
/// <param name="okButtonContent">确定按钮内容</param>
/// <param name="cancelButtonContent">取消按钮内容</param>
public static void ShowConfirmMessageBox(string strContent, EventHandler<WindowClosedEventArgs> onClosed, string okButtonContent, string cancelButtonContent)
{
Style style = Application.Current.Resources["MessageConfirmStyle"] as Style;
RadWindow.Confirm(new DialogParameters()
{
Owner = Application.Current.MainWindow,
Header = "确认",
ContentStyle = style,
Content = new TextBlock() { Text = strContent ,TextWrapping = TextWrapping.Wrap,VerticalAlignment = VerticalAlignment.Center},
Closed = onClosed,
OkButtonContent = okButtonContent,
CancelButtonContent = cancelButtonContent,
});
}
/// <summary>
/// 输入确认对话框
/// 默认以OK,Cancel作为按键
/// </summary>
/// <param name="strContent">内容</param>
/// <param name="onClosed">关闭事件 案例:new EventHandler WindowClosedEventArgs(OnClosed))</param>
public static void ShowPromptMessageBox(string strContent,EventHandler<WindowClosedEventArgs> onClosed)
{
ShowPromptMessageBox(strContent, onClosed, "确定", "取消");
}
/// <summary>
/// 输入确认对话框
/// </summary>
/// <param name="strContent">内容</param>
/// <param name="onClosed">关闭事件 案例:new EventHandler WindowClosedEventArgs(OnClosed))</param>
/// <param name="okButtonContent">确定按钮内容</param>
/// <param name="cancelButtonContent">取消按钮内容</param>
public static void ShowPromptMessageBox(string strContent,EventHandler<WindowClosedEventArgs> onClosed,string okButtonContent, string cancelButtonContent)
{
DialogParameters dialogParameters = new DialogParameters();
dialogParameters.Owner = Application.Current.MainWindow;
dialogParameters.Header = "确认";
dialogParameters.Content = strContent;
dialogParameters.OkButtonContent = okButtonContent;
dialogParameters.CancelButtonContent = cancelButtonContent;
dialogParameters.Closed = onClosed;
RadWindow.Prompt(dialogParameters);
}