/// <summary> /// Set the image to be displayed in the messagebox /// </summary> /// <param name="image"></param> private void SetImageSource(MsgBoxImage image) { string resourceAssembly = Assembly.GetAssembly(typeof(MsgBoxViewModel)).GetName().Name; string folder = "Images/MsgBoxImages/"; // Tango Icon set: http://commons.wikimedia.org/wiki/Tango_icons // Default image displayed in message box string source = string.Format("pack://application:,,,/{0};component/{1}48px-Dialog-information_on.svg.png", resourceAssembly, folder); try { source = string.Format("pack://application:,,,/{0};component/{1}{2}", resourceAssembly, folder, MsgBoxViewModel.msgBoxImageResourcesUris[(int)image]); } catch (Exception) { } Uri imageUri = new Uri(source, UriKind.RelativeOrAbsolute); this.MessageImageSource = new BitmapImage(imageUri); }
/// <summary> /// Class constructor /// </summary> /// <param name="caption"></param> /// <param name="messageBoxText"></param> /// <param name="innerMessage"></param> /// <param name="buttonOption"></param> /// <param name="image"></param> /// <param name="defaultButton"></param> /// <param name="helpLink"></param> /// <param name="helpLinkTitle"></param> /// <param name="navigateHelplinkMethod"></param> /// <param name="enableCopyFunction"></param> internal MsgBoxViewModel(string messageBoxText, string caption, string innerMessage, MsgBoxButtons buttonOption, MsgBoxImage image, MsgBoxResult defaultButton = MsgBoxResult.None, object helpLink = null, string helpLinkTitle = "", Func <object, bool> navigateHelplinkMethod = null, bool enableCopyFunction = false) { this.Title = caption; this.Message = messageBoxText; this.InnerMessageDetails = innerMessage; this.SetButtonVisibility(buttonOption); this.mIsDefaultButton = this.SetupDefaultButton(buttonOption, defaultButton); this.SetImageSource(image); this.mHelpLink = helpLink; this.mHelpLinkTitle = helpLinkTitle; this.mResult = MsgBoxResult.None; this.mDialogCloseResult = null; if (navigateHelplinkMethod != null) { this.mNavigateHyperlinkMethod = navigateHelplinkMethod; } this.EnableCopyFunction = enableCopyFunction; }
public static MsgBoxResult Show(string messageBoxText, string caption, string details, MsgBoxButtons buttonOption, MsgBoxImage image, MsgBoxResult btnDefault = MsgBoxResult.None, object helpLink = null, string helpLinkTitle = "", string helpLabel = "", Func <object, bool> navigateHelplinkMethod = null, bool enableCopyFunction = false) { // Construct the message box viewmodel ViewModel.MsgBoxViewModel viewModel = new ViewModel.MsgBoxViewModel(messageBoxText, caption, details, buttonOption, image, btnDefault, helpLink, helpLinkTitle, navigateHelplinkMethod, enableCopyFunction); viewModel.HyperlinkLabel = helpLabel; // Construct the message box view and add the viewmodel to it MsgBox.mMessageBox = new MsgBox(); MsgBox.mMessageBox.DataContext = viewModel; MsgBox.mMessageBox.ShowDialog(); return(viewModel.Result); }
/// <summary> /// This function does the actual conversion from enum to <seealso cref="Visibility"/>. /// </summary> /// <param name="image"></param> /// <returns>Visibility.Collapsed for MsgBoxImage.None or Visibility.Visible for all others.</returns> public Visibility SetImageSource(MsgBoxImage image) { if (image == MsgBoxImage.None) { return(Visibility.Collapsed); } return(Visibility.Visible); }
public static MsgBoxResult Show(Exception exp, string caption, MsgBoxButtons buttonOption, MsgBoxImage image, MsgBoxResult btnDefault = MsgBoxResult.None, object helpLink = null, string helpLinkTitle = "", string helpLabel = "", Func <object, bool> navigateHelplinkMethod = null, bool enableCopyFunction = false) { string sMess = "Unknown error occured."; string messageBoxText = string.Empty; if (true) { try { messageBoxText = exp.Message; Exception innerEx = exp.InnerException; for (int i = 0; innerEx != null; i++, innerEx = innerEx.InnerException) { string spaces = string.Empty; for (int j = 0; j < i; j++) { spaces += " "; } messageBoxText += "\n" + spaces + "+->" + innerEx.Message; } sMess = exp.ToString(); } catch { } } // Construct the message box viewmodel ViewModel.MsgBoxViewModel viewModel = new ViewModel.MsgBoxViewModel(messageBoxText, caption, sMess, buttonOption, image, btnDefault, helpLink, helpLinkTitle, navigateHelplinkMethod, enableCopyFunction); viewModel.HyperlinkLabel = helpLabel; // Construct the message box view and add the viewmodel to it MsgBox.mMessageBox = new MsgBox(); MsgBox.mMessageBox.DataContext = viewModel; MsgBox.mMessageBox.ShowDialog(); return(viewModel.Result); }
public static MsgBoxResult Show(string messageBoxText, string caption, MsgBoxImage image, MsgBoxResult btnDefault = MsgBoxResult.None, object helpLink = null, string helpLinkTitle = "", string helpLabel = "", Func <object, bool> navigateHelplinkMethod = null, bool enableCopyFunction = false) { return(Show(messageBoxText, caption, string.Empty, MsgBoxButtons.OK, image, btnDefault, helpLink, helpLinkTitle, helpLabel, navigateHelplinkMethod, enableCopyFunction)); }
MsgBoxResult IMsgBoxService.Show(string messageBoxText, string caption, MsgBoxButtons buttonOption, MsgBoxImage image, MsgBoxResult btnDefault, object helpLink, string helpLinkTitle, string helpLinkLabel, Func <object, bool> navigateHelplinkMethod, bool showCopyMessage) { return(View.MsgBox.Show(messageBoxText, caption, buttonOption, image, btnDefault, helpLink, helpLinkTitle, helpLinkLabel, navigateHelplinkMethod, showCopyMessage)); }
MsgBoxResult IMsgBoxService.Show(Exception exp, string caption, MsgBoxButtons buttonOption, MsgBoxImage image, MsgBoxResult btnDefault = MsgBoxResult.None, object helpLink = null, string helpLinkTitle = "", string helpLabel = "", Func <object, bool> navigateHelplinkMethod = null, bool showCopyMessage = false) { return(View.MsgBox.Show(exp, caption, buttonOption, image, btnDefault, helpLink, helpLinkTitle, helpLabel, navigateHelplinkMethod, showCopyMessage)); }
/// <summary> /// Class constructor from parameters. /// </summary> /// <param name="caption"></param> /// <param name="messageBoxText"></param> /// <param name="innerMessage"></param> /// <param name="buttonOption"></param> /// <param name="image"></param> /// <param name="defaultButton"></param> /// <param name="helpLink"></param> /// <param name="helpLinkTitle"></param> /// <param name="navigateHelplinkMethod"></param> /// <param name="enableCopyFunction"></param> /// <param name="defaultCloseResult">Determines the result if user closes a dialog with Esc, F4, or Window close button (X)</param> /// <param name="dialogCanCloseViaChrome">Determines whether user can close dialog via Esc, F4, or Window close button (X)</param> internal MsgBoxViewModel(string messageBoxText, string caption, string innerMessage, MsgBoxButtons buttonOption, MsgBoxImage image, MsgBoxResult defaultButton = MsgBoxResult.None, object helpLink = null, string helpLinkTitle = "", Func <object, bool> navigateHelplinkMethod = null, bool enableCopyFunction = false, MsgBoxResult defaultCloseResult = MsgBoxResult.None, bool dialogCanCloseViaChrome = true) { this.mButtonOption = buttonOption; this.Title = caption; this.Message = messageBoxText; this.InnerMessageDetails = innerMessage; // Enable Copy should be set before button options since button options should // be able to over rule the enableCopyFunction parameter this.EnableCopyFunction = enableCopyFunction; this.SetButtonVisibility(buttonOption); this.IsDefaultButton = this.SetupDefaultButton(buttonOption, defaultButton); this.TypeOfImage = image; this.mHelpLink = helpLink; this.HelpLinkTitle = helpLinkTitle; this.Result = MsgBoxResult.None; this.DefaultCloseResult = defaultCloseResult; this.DialogCanCloseViaChrome = dialogCanCloseViaChrome; this.mDialogCloseResult = null; if (navigateHelplinkMethod != null) { this.mNavigateHyperlinkMethod = navigateHelplinkMethod; } }
public IObservable <MsgBoxResult> ShowMessageBox(System.Windows.Window?owner, string text, string caption, MsgBoxButton button, MsgBoxImage icon) { return(CurrentDispatcher.InvokeAsync(() => (MsgBoxResult)MessageBox.Show(owner ?? _mainWindow, text, caption, (MessageBoxButton)button, (MessageBoxImage)icon))); }
private TaskDialogIcon TranslateIcon(MsgBoxImage icon) { switch (icon) { case MsgBoxImage.None: return TaskDialogIcon.Custom; case MsgBoxImage.Error: return TaskDialogIcon.Error; case MsgBoxImage.Question: return TaskDialogIcon.Shield; case MsgBoxImage.Warning: return TaskDialogIcon.Warning; case MsgBoxImage.Information: return TaskDialogIcon.Information; default: throw new ArgumentOutOfRangeException("icon"); } }
public MsgBoxResult ShowTaskDialog( IWindow owner, string text, string caption, MsgBoxButton button, MsgBoxImage icon, Icon custumIcon) { return ObservableObject.CurrentDispatcher.Invoke( () => { var dialog = new TaskDialog { CenterParent = true, Content = text, ExpandFooterArea = false, ExpandedByDefault = false, MinimizeBox = false, ProgressBarStyle = ProgressBarStyle.None, WindowIcon = custumIcon, WindowTitle = caption, MainInstruction = caption, MainIcon = TranslateIcon(icon) }; TranslateButtons(button, dialog.Buttons); TaskDialogButton clickedButton = dialog.ShowDialog(owner != null ? (Window) owner .TranslateForTechnology () : null); switch (clickedButton.ButtonType) { case ButtonType.Ok: return MsgBoxResult.Ok; case ButtonType.Yes: return MsgBoxResult.Yes; case ButtonType.No: return MsgBoxResult.No; case ButtonType.Cancel: return MsgBoxResult.Cancel; case ButtonType.Close: return MsgBoxResult.Cancel; default: throw new ArgumentOutOfRangeException(); } }); }
public MsgBoxResult ShowMessageBox( IWindow owner, string text, string caption, MsgBoxButton button, MsgBoxImage icon, Icon custumIcon) { Window realWindow = owner == null ? null : (Window)owner.TranslateForTechnology(); return ObservableObject.CurrentDispatcher.Invoke( () => !TaskDialog.OSSupportsTaskDialogs ? (MsgBoxResult) MessageBox.Show( realWindow, text, caption, (MessageBoxButton) button, (MessageBoxImage) icon) : ShowTaskDialog(owner, text, caption, button, icon, custumIcon)); }
/// <summary> /// The show task dialog. /// </summary> /// <param name="owner"> /// The owner. /// </param> /// <param name="text"> /// The text. /// </param> /// <param name="caption"> /// The caption. /// </param> /// <param name="button"> /// The button. /// </param> /// <param name="icon"> /// The icon. /// </param> /// <param name="custumIcon"> /// The custum icon. /// </param> /// <returns> /// The <see cref="MsgBoxResult" />. /// </returns> public MsgBoxResult ShowTaskDialog( IWindow owner, string text, string caption, MsgBoxButton button, MsgBoxImage icon, Icon custumIcon) { Contract.Requires<ArgumentNullException>(text != null, "text"); Contract.Requires<ArgumentNullException>(caption != null, "caption"); return MsgBoxResult.Cancel; }
/// <summary> /// The show message box. /// </summary> /// <param name="owner"> /// The owner. /// </param> /// <param name="text"> /// The text. /// </param> /// <param name="caption"> /// The caption. /// </param> /// <param name="button"> /// The button. /// </param> /// <param name="icon"> /// The icon. /// </param> /// <param name="custumIcon"> /// The custum icon. /// </param> /// <returns> /// The <see cref="MsgBoxResult" />. /// </returns> /// <exception cref="NotImplementedException"> /// </exception> public MsgBoxResult ShowMessageBox( IWindow owner, string text, string caption, MsgBoxButton button, MsgBoxImage icon, Icon custumIcon) { Contract.Requires<ArgumentNullException>(text != null, "text"); Contract.Requires<ArgumentNullException>(caption != null, "caption"); throw new NotImplementedException(); }
/// <summary> /// This function does the actual conversion from enum to <seealso cref="BitmapImage"/>. /// </summary> /// <param name="image"></param> /// <returns></returns> public BitmapImage SetImageSource(MsgBoxImage image) { BitmapImage ret = null; switch (image) { case MsgBoxImage.Information: ret = this.GetApplicationResource("MsgBoxImage_Information"); break; case MsgBoxImage.Question: ret = this.GetApplicationResource("MsgBoxImage_Question"); break; case MsgBoxImage.Error: ret = this.GetApplicationResource("MsgBoxImage_Error"); break; case MsgBoxImage.OK: ret = this.GetApplicationResource("MsgBoxImage_OK"); break; case MsgBoxImage.Alert: ret = this.GetApplicationResource("MsgBoxImage_Alert"); break; case MsgBoxImage.Default: ret = this.GetApplicationResource("MsgBoxImage_Default"); break; case MsgBoxImage.Warning: ret = this.GetApplicationResource("MsgBoxImage_Warning"); break; case MsgBoxImage.Default_OffLight: ret = this.GetApplicationResource("MsgBoxImage_Default_OffLight"); break; case MsgBoxImage.Default_RedLight: ret = this.GetApplicationResource("MsgBoxImage_Default_RedLight"); break; case MsgBoxImage.Information_Orange: ret = this.GetApplicationResource("MsgBoxImage_Information_Orange"); break; case MsgBoxImage.Information_Red: ret = this.GetApplicationResource("MsgBoxImage_Information_Red"); break; case MsgBoxImage.Process_Stop: ret = this.GetApplicationResource("MsgBoxImage_Process_Stop"); break; case MsgBoxImage.None: return(null); default: throw new NotImplementedException(image.ToString()); } // just return dynamic resource if we found one // otherwise fall-through here and return back up image if (ret != null) { return(ret); } string resourceAssembly = Assembly.GetAssembly(typeof(MsgBoxViewModel)).GetName().Name; string folder = "MsgBox/Images/MsgBoxImages/"; // Tango Icon set: http://commons.wikimedia.org/wiki/Tango_icons // Default image displayed in message box string source = string.Format("pack://application:,,,/{0};component/{1}48px-Dialog-information_on.svg.png", resourceAssembly, folder); try { source = string.Format("pack://application:,,,/{0};component/{1}{2}", resourceAssembly, folder, ImageEnumToImageConverter.msgBoxImageResourcesUris[(int)image]); } catch (Exception) { } Uri imageUri = new Uri(source, UriKind.RelativeOrAbsolute); return(new BitmapImage(imageUri)); }