Exemplo n.º 1
0
        public static bool ShowModalDialog(this Dialog dialog)
        {
            Utility.FadeIn();
            var res = dialog.ShowDialog();

            Utility.FadeOut();

            return(res.IsTrue());
        }
Exemplo n.º 2
0
        private static void BeginOpenAnimation(Window window, Notification slot)
        {
            // Can't be proven
            Contract.Assume(window != null);

            switch (slot.Animation)
            {
            case Animation.None:
                break;

            case Animation.Fade:
                window.Opacity = 0;
                break;

            case Animation.Slide:
                window.Left = slot.HiddenPosition.X;
                window.Top  = slot.HiddenPosition.Y;
                break;
            }
        }
Exemplo n.º 3
0
        private static void CloseAnimation(Window window, Notification slot)
        {
            // Can't be proven
            Contract.Assume(window != null);

            switch (slot.Animation)
            {
            case Animation.None:
                break;

            case Animation.Fade:
                window.BeginAnimation(UIElement.OpacityProperty,
                                      new DoubleAnimation(1d, 0d, new Duration(TimeSpan.FromSeconds(0.2))));
                break;

            case Animation.Slide:
                window.BeginAnimation(System.Windows.Window.LeftProperty,
                                      new DoubleAnimation(slot.HiddenPosition.X, new Duration(TimeSpan.FromSeconds(0.2))));
                window.BeginAnimation(System.Windows.Window.TopProperty,
                                      new DoubleAnimation(slot.HiddenPosition.Y, new Duration(TimeSpan.FromSeconds(0.2))));
                break;
            }
        }
Exemplo n.º 4
0
        public static void Push(string message, [CanBeNull] string remark)
        {
            ValidationHelper.NotNullOrWhitespace(message, "message");

            Window window = null;

            try
            {
                window = new Window
                {
                    Title         = message,
                    Focusable     = false,
                    ShowActivated = false,
                    ShowInTaskbar = false,
                    Topmost       = true,
                    WindowStyle   = WindowStyle.ToolWindow
                };
                if (!string.IsNullOrWhiteSpace(remark))
                {
                    window.Content = new TextBlock {
                        Margin = new Thickness(10d, 5d, 10d, 5d), Text = remark
                    };
                }

                var slot = Reserve();

                window.Left   = slot.Position.X;
                window.Top    = slot.Position.Y;
                window.Width  = slot.Size.Width;
                window.Height = slot.Size.Height;

                // Capture closure
                var closingSlot = slot;
                var timer       = new Timer(delegate
                {
                    closingSlot = slot;
                    window.Dispatcher.Invoke(window.Close, DispatcherPriority.Normal);
                });

                window.Closing += (s, e) =>
                {
                    closingSlot = slot;
                    timer.Dispose();
                    Free(closingSlot.ID);
                    CloseAnimation(window, closingSlot);
                };

                BeginOpenAnimation(window, slot);
                window.Show();
                EndOpenAnimation(window, slot);

                window.BeginAnimation(Window.ProgressProperty, new DoubleAnimation(100d, 0d, slot.Lifetime));

                timer.Change((int)Math.Ceiling(slot.Lifetime.TotalMilliseconds), -1);
            }
            catch (ServerUnavailableException)
            {
                if (window != null)
                {
                    window.Close();
                }
                throw;
            }
            catch (Exception exception)
            {
                if (window != null)
                {
                    window.Close();
                }
                throw new PushNotificationFailedException("Push notification failed.", exception);
            }
        }