Exemplo n.º 1
0
        /// <summary>
        /// Shows the window delayed by using the <see cref="MinimumDurationBeforeShow"/>.
        /// </summary>
        private void ShowWindow()
        {
            if (PleaseWaitWindow != null)
            {
                return;
            }

            PleaseWaitWindow          = new PleaseWaitWindow();
            PleaseWaitWindow.Text     = _currentStatusText;
            PleaseWaitWindow.MinWidth = double.IsNaN(_currentWindowWidth) ? 0d : _currentWindowWidth;

            PleaseWaitWindow.Show();

            while (!PleaseWaitWindow.IsOwnerDimmed)
            {
                // It's a bad practice to use this "equivalent" of DoEvents in WPF, but I don't see another choice
                // to wait until the animation of the ShowWindow has finished without blocking the UI
                PleaseWaitWindow.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate { });
                PleaseWaitWindow.UpdateLayout();
            }

            lock (_visibleStopwatchLock)
            {
                if (_visibleStopwatch == null)
                {
                    _visibleStopwatch = new Stopwatch();
                    _visibleStopwatch.Start();
                }
                else
                {
                    _visibleStopwatch.Reset();
                    _visibleStopwatch.Start();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the status text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="windowWidth">Width of the window.</param>
        private void UpdateStatusText(string text, double windowWidth)
        {
            _currentStatusText  = text;
            _currentWindowWidth = windowWidth;

            if (PleaseWaitWindow == null)
            {
                return;
            }

            if (!PleaseWaitWindow.Dispatcher.CheckAccess())
            {
                PleaseWaitWindow.Dispatcher.Invoke(new UpdateStatusTextDelegate(UpdateStatusText), new object[] { text, windowWidth });
                return;
            }

            PleaseWaitWindow.Text     = _currentStatusText;
            PleaseWaitWindow.MinWidth = double.IsNaN(_currentWindowWidth) ? 0d : _currentWindowWidth;
            PleaseWaitWindow.UpdateLayout();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Hides the window.
        /// </summary>
        private void HideWindow()
        {
            if (PleaseWaitWindow == null)
            {
                return;
            }

            if (!PleaseWaitWindow.Dispatcher.CheckAccess())
            {
                PleaseWaitWindow.Dispatcher.Invoke((HideWindowDelegate)HideWindow, new object[] { });
                return;
            }


            // Hide the window, this will start the animation to undimm the parent and then the please wait window
            // will close itself
            PleaseWaitWindow.Hide();
            PleaseWaitWindow = null;

            _currentStatusText  = "Please wait...";
            _currentWindowWidth = 0d;
        }
        /// <summary>
        /// Shows the window delayed by using the <see cref="MinimumDurationBeforeShow"/>.
        /// </summary>
        private void ShowWindow()
        {
            if (PleaseWaitWindow != null)
            {
                return;
            }

            PleaseWaitWindow = new PleaseWaitWindow();
            PleaseWaitWindow.Text = _currentStatusText;
            PleaseWaitWindow.MinWidth = double.IsNaN(_currentWindowWidth) ? 0d : _currentWindowWidth;
            
            PleaseWaitWindow.Show();

            while (!PleaseWaitWindow.IsOwnerDimmed)
            {
                // It's a bad practice to use this "equivalent" of DoEvents in WPF, but I don't see another choice
                // to wait until the animation of the ShowWindow has finished without blocking the UI
                PleaseWaitWindow.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart)delegate { });
                PleaseWaitWindow.UpdateLayout();
            }

            lock (_visibleStopwatchLock)
            {
                if (_visibleStopwatch == null)
                {
                    _visibleStopwatch = new Stopwatch();
                    _visibleStopwatch.Start();
                }
                else
                {
                    _visibleStopwatch.Reset();
                    _visibleStopwatch.Start();
                }
            }
        }