| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System.Windows;
- using System.Windows.Media;
- namespace Muchinfo.MTPClient.Infrastructure.MessageBox
- {
- public class MessageBoxHelper
- {
- /// <summary>
- /// 显示成功信息
- /// </summary>
- /// <param name="message">提示信息</param>
- /// <param name="caption">标题</param>
- /// <param name="isLogin">if set to <c>true</c> [is login].</param>
- /// <returns>MessageBoxResult.</returns>
- public static MessageBoxResult ShowSuccess(string message, string caption, bool isLogin = false)
- {
- return ShowSuccess(Application.Current.MainWindow, message, caption, isLogin);
- }
- /// <summary>
- /// Shows the success.
- /// </summary>
- /// <param name="owner">The owner.</param>
- /// <param name="message">The message.</param>
- /// <param name="caption">The caption.</param>
- /// <param name="isLogin">if set to <c>true</c> [is login].</param>
- /// <returns>MessageBoxResult.</returns>
- public static MessageBoxResult ShowSuccess(Window owner, string message, string caption, bool isLogin = false)
- {
- var background = GetBackground(isLogin);
- return NewMessageBox.Show(owner, message, caption, MessageBoxButton.OK, MessageBoxImage.Information, background);
- }
- /// <summary>
- /// 显示提示信息
- /// </summary>
- /// <param name="message">提示信息</param>
- /// <param name="caption">标题</param>
- /// <param name="isLogin">if set to <c>true</c> [is login].</param>
- /// <returns>MessageBoxResult.</returns>
- public static MessageBoxResult ShowInfo(string message, string caption, bool isLogin = false)
- {
- return ShowInfo(Application.Current.MainWindow, message, caption, isLogin);
- }
- /// <summary>
- /// Shows the information.
- /// </summary>
- /// <param name="owner">The owner.</param>
- /// <param name="message">The message.</param>
- /// <param name="caption">The caption.</param>
- /// <param name="isLogin">if set to <c>true</c> [is login].</param>
- /// <returns>MessageBoxResult.</returns>
- public static MessageBoxResult ShowInfo(Window owner, string message, string caption, bool isLogin = false)
- {
- var background = GetBackground(isLogin);
- return NewMessageBox.Show(owner, message, caption, MessageBoxButton.OK, MessageBoxImage.Warning, background);
- }
- /// <summary>
- /// 显示选择信息
- /// </summary>
- /// <param name="message">提示信息</param>
- /// <param name="caption">标题</param>
- /// <param name="isLogin">if set to <c>true</c> [is login].</param>
- /// <returns>System.Windows.MessageBoxResult.</returns>
- public static MessageBoxResult ShowQuestion(string message, string caption, bool isLogin = false)
- {
- return ShowQuestion(Application.Current.MainWindow, message, caption, isLogin);
- }
- /// <summary>
- /// Shows the question.
- /// </summary>
- /// <param name="owner">The owner.</param>
- /// <param name="message">The message.</param>
- /// <param name="caption">The caption.</param>
- /// <param name="isLogin">if set to <c>true</c> [is login].</param>
- /// <returns>MessageBoxResult.</returns>
- public static MessageBoxResult ShowQuestion(Window owner, string message, string caption, bool isLogin = false)
- {
- var background = GetBackground(isLogin);
- return NewMessageBox.Show(owner, message, caption, MessageBoxButton.YesNo, MessageBoxImage.Question, background);
- }
- private static Brush GetBackground(bool isLogin)
- {
- return GetFromeResource<SolidColorBrush>(isLogin ? "MuchinfoBrush3" : "MuchinfoBrush6");
- }
- private static T GetFromeResource<T>(string resourceName) where T : class
- {
- try
- {
- var brush = (T)Application.Current.TryFindResource(resourceName);
- if (brush == null) return default(T);
- return brush;
- }
- catch
- {
- return null;
- }
- }
- }
- }
|