public MessageBoxViewModel(MessageBox manager, MessageBoxConfiguration options) { _configuration = options; DetailText = options.DetailText; SummaryText = options.SummaryText; // If there is no caption, then just put the caption-prefix without the spacer. if (StringLib.HasNothing(options.CaptionAfterPrefix)) { if (StringLib.HasNothing(options.CaptionPrefix)) { Title = manager.CaptionPrefix; } else { Title = options.CaptionPrefix; } } else { if (StringLib.HasNothing(options.CaptionPrefix)) { Title = manager.CaptionPrefix + ": " + options.CaptionAfterPrefix; } else { Title = options.CaptionPrefix + ": " + options.CaptionAfterPrefix; } } IsCustomElementVisible = true; IsGradiantShown = false; SummaryTextColor = new SolidColorBrush(Colors.Black); }
/// <summary> /// The Copy-Constructor. This does NOT copy the SummaryText or DetailText. /// </summary> /// <param name="source">the MessageBoxConfiguration object to copy the values from</param> public MessageBoxConfiguration(MessageBoxConfiguration source) { this._buttonFlags = source._buttonFlags; // this._captionPrefix = source.CaptionPrefix; this._captionAfterPrefix = source.CaptionAfterPrefix; this._isToCenterOverParent = source.IsToCenterOverParent; this._isToBeTopmostWindow = source.IsToBeTopmostWindow; this._messageType = source.MessageType; this._timeoutPeriodInSeconds = source.TimeoutPeriodInSeconds; }
public MessageBoxViewModel() { //CBL But how to get logging when Application.Current does NOT yield my App, as within Cider? //var logManager = new NLogManagerWrapper(); //logManager.GetLogger("MessageBoxLogger").LogInfo("enter MessageBoxViewModel.ctor, IsInDesignMode=" + this.IsInDesignMode); #if DEBUG var loggingProvider = Application.Current as ISimpleLoggingProvider; if (loggingProvider != null) { //loggingProvider.LogManager.GetLogger("MessageBoxLogger").LogInfo("enter MessageBoxViewModel.ctor, IsInDesignMode=" + this.IsInDesignMode); loggingProvider.LogInfo("enter MessageBoxViewModel.ctor, IsInDesignMode=" + this.IsInDesignMode); } #endif if (this.IsInDesignMode) { _configuration = new MessageBoxConfiguration(MessageBoxType.Error); Configuration.ButtonFlags = MessageBoxButtons.Yes | MessageBoxButtons.No | MessageBoxButtons.Ok | MessageBoxButtons.Cancel | MessageBoxButtons.Close | MessageBoxButtons.Ignore | MessageBoxButtons.Retry; Title = "Vendor Product: Caption"; //string summaryTextPattern = "The Summary Text."; //SummaryText = summaryTextPattern.ExpandTo(20); SummaryText = "This is the SummaryText right here. Right here."; string detailTextPattern = "The Details Texts. X"; DetailText = detailTextPattern.ExpandTo(63); //DetailText = "The Details Texts. XThe Details Texts. XThe Details Texts._XThe Details Texts._XThe Details Texts._XThe"; //DetailText = "The Details Text"; //Configuration.BackgroundTexture = MessageBoxBackgroundTexturePreset.BlueTexture; DefaultConfiguration.IsUsingNewerIcons = false; IsCustomElementVisible = true; IsGradiantShown = false; SummaryTextColor = new SolidColorBrush(Colors.Black); } IsCustomElementVisible = true; IsGradiantShown = false; SummaryTextColor = new SolidColorBrush(Colors.Black); }
/// <summary> /// Create a new MessageBoxWindow, with the given options if non-null - otherwise use the DefaultOptions. /// </summary> /// <param name="options">The options to use for this particular message-box invocation. Set this to null to use the DefaultOptions.</param> public MessageBoxWindow(MessageBox mgr, MessageBoxConfiguration options) { //Console.WriteLine("MessageBoxWindow ctor, with options.BackgroundTexture = " + options.BackgroundTexture.ToString()); _manager = mgr; // _options has to be set before InitializeComponent, since that causes properties to be bound, and hence the DataContext creates it's view-model. if (options == null) { _options = mgr.Configuration; } else { _options = options; } _viewModel = MessageBoxViewModel.GetInstance(mgr, _options); InitializeComponent(); // Ensure the timeout value isn't ridiculously high (as when the caller mistakenly thinks it's in milliseconds). // Use the constant upper-limit value to test it against. if (_options.TimeoutPeriodInSeconds > MessageBoxConfiguration.MaximumTimeoutPeriodInSeconds) { _options.TimeoutPeriodInSeconds = MessageBoxConfiguration.MaximumTimeoutPeriodInSeconds; } else if (_options.TimeoutPeriodInSeconds == 0) { // Since it was given a zero timeout -- assign the actual default value that it should be for this type. _options.TimeoutPeriodInSeconds = MessageBox.DefaultConfiguration.GetDefaultTimeoutValueFor(_options.MessageType); } if (_options.IsToCenterOverParent) { this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner; } // If the option to use custom styles for the buttons is turned off, then set these button styles to null // so that they do not inherit the styles of the parent application. if (!MessageBox.DefaultConfiguration.IsCustomButtonStyles) { btnCancel.Style = btnClose.Style = btnNo.Style = btnOk.Style = btnRetry.Style = btnYes.Style = btnIgnore.Style = null; } #if SILVERLIGHT _viewModel.CopyCommand = new RelayCommand( () => OnCopyCommandExecuted() ); _viewModel.StayCommand = new RelayCommand( () => OnStayCommandExecuted(), () => StayCommand_CanExecute() ); #else _viewModel.CopyCommand = new RelayCommand( (x) => OnCopyCommandExecuted() ); _viewModel.StayCommand = new RelayCommand( (x) => OnStayCommandExecuted(), (x) => StayCommand_CanExecute() ); #endif Loaded += OnLoaded; #if SILVERLIGHT Closing += new EventHandler<System.ComponentModel.CancelEventArgs>(OnClosing); #else ContentRendered += OnContentRendered; Closing += new System.ComponentModel.CancelEventHandler(OnClosing); #endif }
public static MessageBoxViewModel GetInstance(MessageBox manager, MessageBoxConfiguration options) { _theInstance = new MessageBoxViewModel(manager, options); return _theInstance; }
//CBL Added this. Trying to update how the view-model works. #region Init /// <summary> /// Initialize this object's properties from the given manager and options. /// Call this before the MessageBoxWindow is loaded (ie, the Loaded event gets raised). /// </summary> /// <param name="manager">the MessageBox object that serves as a manager of the message-box facility</param> /// <param name="options">a MessageBoxConfiguration to get the options from</param> internal void Init(MessageBox manager, MessageBoxConfiguration options) { Configuration = options; DetailText = options.DetailText; SummaryText = options.SummaryText; // If there is no caption, then just put the caption-prefix without the spacer. if (StringLib.HasNothing(options.CaptionAfterPrefix)) { if (StringLib.HasNothing(options.CaptionPrefix)) { Title = manager.CaptionPrefix; } else { Title = options.CaptionPrefix; } } else // the caption-suffix is not empty. { if (StringLib.HasNothing(options.CaptionPrefix)) { Title = manager.CaptionPrefix + ": " + options.CaptionAfterPrefix; } else { Title = options.CaptionPrefix + ": " + options.CaptionAfterPrefix; } } // Cause all of the property binding values to be retrieved again // that depend upon the _configuration choices. Notify("BackgroundBrush"); Notify("ButtonMargin"); Notify("ButtonCount"); Notify("ButtonWidth"); Notify("ButtonPanelBackground"); Notify("ButtonCancelVisibility"); Notify("ButtonCloseVisibility"); Notify("ButtonIgnoreVisibility"); Notify("ButtonOkVisibility"); Notify("ButtonRetryVisibility"); Notify("ButtonYesVisibility"); Notify("ButtonNoVisibility"); Notify("Height"); Notify("SummaryTextColor"); Notify("SummaryTextBackground"); Notify("SummaryTextHorizontalContentAlignment"); Notify("SummaryTextMargin"); Notify("SummaryTextRowSpan"); Notify("DetailTextBackground"); Notify("DetailTextHorizontalContentAlignment"); Notify("DetailTextVerticalAlignment"); Notify("DetailTextMargin"); Notify("GradiantLeftColor"); Notify("GradiantRightColor"); Notify("IconImage"); Notify("IconMargin"); Notify("UpperRectangleRowSpan"); Notify("UpperRectangleVisibility"); }