コード例 #1
0
        /// <summary>
        /// Handle the ContentRendered event, which occurrs after the UI elements have been rendered on-screen.
        /// </summary>
        void OnContentRendered(object sender, EventArgs e)
        {
            #region Make me the top-most window.

            if (!this.IsTesting)
            {
                if (_options.IsToBeTopmostWindow)
                {
#if !SILVERLIGHT
                    this.Topmost = true;
                    this.Focus();
#endif
                }
            }
            #endregion

            #region Audial effects

            if (!this.IsTesting && _options.IsSoundEnabled)
            {
                if (!_options.IsUsingNewerSoundScheme)
                {
                    JhMessageBoxWindow.MessageBeep(_options.MessageType);
                }
                else
                {
                    //TODO: How to implement this in SL?
#if !SILVERLIGHT
                    switch (_options.MessageType)
                    {
                    case JhMessageBoxType.Information:
                        AudioLib.PlaySoundResourceEvenIfNotPCM(_informationSoundResource);
                        break;

                    case JhMessageBoxType.Question:
                        AudioLib.PlaySoundResourceEvenIfNotPCM(_questionSoundResource);
                        break;

                    case JhMessageBoxType.UserMistake:
                        AudioLib.PlaySoundResource(_userMistakeSoundResource);
                        break;

                    case JhMessageBoxType.Warning:
                        AudioLib.PlaySoundResource(_warningSoundResource);
                        break;

                    case JhMessageBoxType.Error:
                        AudioLib.PlaySoundResource(_errorSoundResource);
                        break;

                    case JhMessageBoxType.SecurityIssue:
                        AudioLib.PlaySoundResource(_securityIssueSoundResource);
                        break;

                    case JhMessageBoxType.Stop:
                        AudioLib.PlaySoundResource(_stopSoundResource);
                        break;
                    }
#endif
                }
            }
            #endregion Audial effects

            #region Timeout

            if (!IsTesting || (IsTesting && !TestFacility.IsToWaitForExplicitClose))
            {
                // Set the timer that will close this message-box.
                int timeoutPeriodToSet = _options.TimeoutPeriodInSeconds;
                if (timeoutPeriodToSet == 0)
                {
                    // If the default value of zero was indicated, that means to use the default value.
                    timeoutPeriodToSet = JhMessageBoxOptions.GetDefaultTimeoutValueFor(_options.MessageType);
                    _options.TimeoutPeriodInSeconds = timeoutPeriodToSet;
                }
                // If we are running tests and this option is set -- limit the timeout to our special, brief time-period.
                if (_manager._testFacility != null && TestFacility.IsTimeoutsFast)
                {
                    if (timeoutPeriodToSet > 1)
                    {
                        timeoutPeriodToSet = 1;
                    }
                }
                StartTimer(timeoutPeriodToSet);
            }

            #endregion Timeout
        }
コード例 #2
0
        /// <summary>
        /// Create a new JhMessageBoxWindow, 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. Leave this null to use the DefaultOptions.</param>
        public JhMessageBoxWindow(JhMessageBox mgr, JhMessageBoxOptions options = null)
        {
            //Console.WriteLine("JhMessageBoxWindow 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.DefaultOptions;
            }
            else
            {
                _options = options;
            }
            _viewModel = JhMessageBoxViewModel.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 > JhMessageBoxOptions.MaximumTimeoutPeriodInSeconds)
            {
                _options.TimeoutPeriodInSeconds = JhMessageBoxOptions.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 (!_options.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
        }