Exemplo n.º 1
0
        public MegaDialog(string title)
            : base()
        {
            this.CloseCommand = new DelegateCommand(this.CloseDialog);

            this.IsFullScreen               = false;
            this.Background                 = new SolidColorBrush(Color.FromArgb(155, 31, 31, 31));
            this.WindowSizeMode             = WindowSizeMode.FitToPlacementTarget;
            this.HorizontalContentAlignment = HorizontalAlignment.Stretch;
            this.VerticalContentAlignment   = VerticalAlignment.Top;
            this.IsAnimationEnabled         = true;
            this.IsClosedOnBackButton       = true;
            this.IsClosedOnOutsideTap       = true;
            this.OpenAnimation              = AnimationService.GetOpenMessageDialogAnimation();
            this.CloseAnimation             = AnimationService.GetCloseMessageDialogAnimation();

            this.WindowOpening += (sender, args) => DialogOpening(args);
            this.WindowClosed  += (sender, args) => DialogClosed();

            this.MainGrid = new Grid()
            {
                Background     = new SolidColorBrush((Color)Application.Current.Resources["PhoneChromeColor"]),
                Width          = Double.NaN,
                RowDefinitions =
                {
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },                                                // Title row
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },                                                // Content row
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },                                                // Buttons row
                }
            };

            this.Title = new TextBlock()
            {
                Text         = title.ToUpper(),
                FontFamily   = new FontFamily("Segoe WP Semibold"),
                FontSize     = Convert.ToDouble(Application.Current.Resources["PhoneFontSizeMedium"]),
                Margin       = new Thickness(20, 12, 20, 20),
                TextWrapping = TextWrapping.Wrap
            };

            this.MainGrid.Children.Add(this.Title);
            Grid.SetRow(this.Title, 0);

            this.Content = this.MainGrid;
        }
        /// <summary>
        /// Display the CustomMessageDialog on screen with the specified parameter from the constructor
        /// </summary>
        public void ShowDialog()
        {
            // Create the base canvas that will hold all the controls and application bar functions
            DialogWindow = new RadModalWindow()
            {
                Name                       = "CustomMessageDialog",
                Background                 = new SolidColorBrush(Color.FromArgb(155, 31, 31, 31)),
                WindowSizeMode             = WindowSizeMode.FitToPlacementTarget,
                VerticalContentAlignment   = VerticalAlignment.Top,                             // Message dialog dispays top of screen
                HorizontalContentAlignment = HorizontalAlignment.Stretch,
                IsClosedOnOutsideTap       = false,                                             // Only close on back button press or button tap
                OpenAnimation              = AnimationService.GetOpenMessageDialogAnimation(),
                CloseAnimation             = AnimationService.GetCloseMessageDialogAnimation(), // need to slide out nicely
            };

            DialogWindow.WindowOpening += (sender, args) => DialogService.DialogOpening(args);
            DialogWindow.WindowClosed  += (sender, args) => DialogService.DialogClosed();

            // Create a Grid to populate with UI controls
            var mainGrid = new Grid()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Top,
                RowDefinitions      =
                {
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },                                               // Optional Image row
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },                                               // Title row
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },                                               // Message row
                    new RowDefinition()
                    {
                        Height = GridLength.Auto
                    },                                               // Response control(s) row
                },
                Margin = new Thickness(24, 0, 24, 0)
            };


            if (_image != null)
            {
                // Add image to the view
                mainGrid.Children.Add(_image);
                Grid.SetRow(_image, 0);
            }

            // Create title label
            var title = new TextBlock()
            {
                Text                = _title.ToUpper(), // The specified title string in uppercase always
                FontFamily          = new FontFamily("Segoe WP Semibold"),
                FontSize            = Convert.ToDouble(Application.Current.Resources["PhoneFontSizeMedium"]),
                Foreground          = new SolidColorBrush((Color)Application.Current.Resources["PhoneForegroundColor"]),
                Margin              = _image == null ? new Thickness(0, 24, 0, 0) : new Thickness(0),
                HorizontalAlignment = HorizontalAlignment.Left,
                TextWrapping        = TextWrapping.Wrap
            };

            // Add title to the view
            mainGrid.Children.Add(title);
            Grid.SetRow(title, 1);

            // Create message label
            var message = new TextBlock()
            {
                Text                = _message, // The specified message
                FontFamily          = new FontFamily("Segoe WP SemiLight"),
                FontSize            = Convert.ToDouble(Application.Current.Resources["PhoneFontSizeMediumLarge"]),
                Foreground          = new SolidColorBrush((Color)Application.Current.Resources["PhoneForegroundColor"]),
                Margin              = _image == null ? new Thickness(0, 50, 0, 48) : new Thickness(0, 36, 0, 36),
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                TextWrapping        = TextWrapping.Wrap // Needed for long strings / texts
            };

            // Add message to the view
            mainGrid.Children.Add(message);
            Grid.SetRow(message, 2);

            // Create response controls panel
            var buttonGrid = new Grid()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Margin = new Thickness(-12, 0, -12, 24)
            };

            // Add response controls to the view
            mainGrid.Children.Add(buttonGrid);
            Grid.SetRow(buttonGrid, 3);

            // Create the response control buttons
            foreach (var dialogButton in _buttons)
            {
                var button = new Button()
                {
                    Content             = dialogButton.Text.ToLower(), // always lower case, modern ui design guideline
                    HorizontalAlignment = HorizontalAlignment.Stretch
                };

                // Focus the button(s) to let the virtual keyboard slide down when it was open
                button.Loaded += (sender, args) => button.Focus();

                var dlgButton = dialogButton;
                button.Tap += (sender, args) =>
                {
                    if (dlgButton.TapAction != null)
                    {
                        // Invoke action after the close animation of the dialog has finished
                        // Used for nice effect of sliding out and see the action
                        DialogWindow.CloseAnimation.Ended += (o, eventArgs) =>
                        {
                            dlgButton.TapAction.Invoke();
                        };

                        // If tap action is defined the dialog result is a custom result
                        this.DialogResult = MessageDialogResult.Custom;

                        // Set result for ShowDialogAsync invocation
                        if (_taskCompletionSource != null)
                        {
                            _taskCompletionSource.TrySetResult(this.DialogResult);
                        }

                        DialogWindow.IsOpen = false;
                    }
                    else
                    {
                        switch (dlgButton.Type)
                        {
                        case MessageDialogButton.Ok:
                        case MessageDialogButton.Yes:
                            this.DialogResult = MessageDialogResult.OkYes;
                            // Set result for ShowDialogAsync invocation
                            if (_taskCompletionSource != null)
                            {
                                _taskCompletionSource.TrySetResult(this.DialogResult);
                            }
                            OnOkOrYesButtonTapped(new EventArgs());
                            break;

                        case MessageDialogButton.Cancel:
                        case MessageDialogButton.No:
                            this.DialogResult = MessageDialogResult.CancelNo;
                            // Set result for ShowDialogAsync invocation
                            if (_taskCompletionSource != null)
                            {
                                _taskCompletionSource.TrySetResult(this.DialogResult);
                            }
                            OnCancelOrNoButtonTapped(new EventArgs());
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }

                        // Set result for ShowDialogAsync invocation
                        if (_taskCompletionSource != null)
                        {
                            _taskCompletionSource.TrySetResult(this.DialogResult);
                        }
                    }
                };

                buttonGrid.Children.Add(button);

                switch (_buttonOrientation)
                {
                case Orientation.Vertical:
                    buttonGrid.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Star)
                    });
                    Grid.SetRow(button, buttonGrid.RowDefinitions.Count - 1);
                    break;

                case Orientation.Horizontal:
                    buttonGrid.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = new GridLength(1, GridUnitType.Star)
                    });
                    Grid.SetColumn(button, buttonGrid.ColumnDefinitions.Count - 1);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            // Used to color the dialog content backgroud
            var border = new Border
            {
                Background          = new SolidColorBrush((Color)Application.Current.Resources["PhoneChromeColor"]),
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Child = mainGrid,
            };

            // Set the content on the canvas and show the dialog
            DialogWindow.Content = border;
            DialogWindow.IsOpen  = true;
        }
Exemplo n.º 3
0
        public MegaDialog(string title = null)
            : base()
        {
            this.CloseCommand = new DelegateCommand(this.CloseDialog);

            this.IsFullScreen               = false;
            this.Background                 = new SolidColorBrush(Color.FromArgb(155, 31, 31, 31));
            this.WindowSizeMode             = WindowSizeMode.FitToPlacementTarget;
            this.HorizontalContentAlignment = HorizontalAlignment.Stretch;
            this.VerticalContentAlignment   = VerticalAlignment.Top;
            this.IsAnimationEnabled         = true;
            this.IsClosedOnBackButton       = true;
            this.IsClosedOnOutsideTap       = true;
            this.OpenAnimation              = AnimationService.GetOpenMessageDialogAnimation();
            this.CloseAnimation             = AnimationService.GetCloseMessageDialogAnimation();

            this.WindowOpening += (sender, args) => DialogOpening(args);
            this.WindowClosed  += (sender, args) => DialogClosed();

            this.MainGrid = new Grid()
            {
                Background     = new SolidColorBrush((Color)Application.Current.Resources["PhoneChromeColor"]),
                Width          = Double.NaN,
                RowDefinitions =
                {
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },                                                                     // Logo row
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },                                                                     // Title row
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Star)
                    },                                                                     // Content row
                    new RowDefinition()
                    {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },                                                                     // Buttons row
                }
            };

            var iconPath = new Path()
            {
                Height              = 24,
                Width               = 24,
                Stretch             = Stretch.Uniform,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Center,
                Margin              = new Thickness(20, 20, 0, 24),
                Fill = new SolidColorBrush((Color)Application.Current.Resources["PhoneForegroundColor"])
            };

            iconPath.SetDataBinding(VisualResources.MEGAIconPathData);

            this.MainGrid.Children.Add(iconPath);
            Grid.SetRow(iconPath, 0);

            if (!string.IsNullOrWhiteSpace(title))
            {
                this.Title = new TextBlock()
                {
                    Text         = title.ToUpper(),
                    FontFamily   = new FontFamily("Segoe WP Semibold"),
                    FontSize     = Convert.ToDouble(Application.Current.Resources["PhoneFontSizeMedium"]),
                    Margin       = new Thickness(20, 0, 20, 20),
                    TextWrapping = TextWrapping.Wrap
                };

                this.MainGrid.Children.Add(this.Title);
                Grid.SetRow(this.Title, 1);
            }

            this.Content = this.MainGrid;
        }