Inheritance: System.Windows.Controls.ContentControl
Beispiel #1
0
        public Task <InputResponse> InputAsync(string message, string placeholder = null, string title = null, string okButton = "OK",
                                               string cancelButton = "Cancel", string initialText      = null)
        {
            var textBox = new PhoneTextBox {
                Hint = placeholder
            };

            var box = new Microsoft.Phone.Controls.CustomMessageBox()
            {
                Caption            = title,
                Message            = message,
                LeftButtonContent  = okButton,
                RightButtonContent = cancelButton,
                Content            = textBox
            };

            var response = new TaskCompletionSource <InputResponse>();

            box.Dismissed += (sender, args) => response.TrySetResult(new InputResponse()
            {
                Ok   = args.Result == CustomMessageBoxResult.LeftButton,
                Text = textBox.Text
            });
            box.Show();
            return(response.Task);
        }
        /// <summary>
        /// Shows a message in the dialog.
        /// </summary>
		/// <param name="message">The message to show.</param>
        public void Show(string message)
        {
            CustomMessageBox messageBox = new CustomMessageBox()
            {
                Message = message
            };

            messageBox.Show();
        }
        /// <summary>
        /// Shows a message with a caption in the dialog.
        /// </summary>
        /// <param name="message">The message to show.</param>
        /// <param name="caption">The caption of the dialog.</param>
        public void Show(string message, string caption)
        {
            CustomMessageBox messageBox = new CustomMessageBox()
            {
                Caption = caption,
                Message = message
            };

            messageBox.Show();
        }
Beispiel #4
0
        public Task <ConfirmThreeButtonsResponse> ConfirmThreeButtonsAsync(string message, string title = null, string positive = "Yes", string negative = "No", string neutral = "Maybe")
        {
            StackPanel contents = new StackPanel();

            contents.Orientation = Orientation.Vertical;
            var positiveButton = new Button()
            {
                Content = positive
            };
            var neutralButton = new Button()
            {
                Content = neutral
            };
            var negativeButton = new Button()
            {
                Content = negative
            };

            contents.Children.Add(positiveButton);
            contents.Children.Add(neutralButton);
            contents.Children.Add(negativeButton);

            var box = new Microsoft.Phone.Controls.CustomMessageBox()
            {
                Caption              = title,
                Message              = message,
                IsLeftButtonEnabled  = false,
                IsRightButtonEnabled = false,
                Content              = contents
            };

            var response = new TaskCompletionSource <ConfirmThreeButtonsResponse>();

            positiveButton.Click += (sender, args) =>
            {
                response.TrySetResult(ConfirmThreeButtonsResponse.Positive);
                box.Dismiss();
            };
            neutralButton.Click += (sender, args) =>
            {
                response.TrySetResult(ConfirmThreeButtonsResponse.Neutral);
                box.Dismiss();
            };
            negativeButton.Click += (sender, args) =>
            {
                response.TrySetResult(ConfirmThreeButtonsResponse.Negative);
                box.Dismiss();
            };
            box.Show();
            return(response.Task);
        }
 public Task AlertAsync(string message, string title = "", string okButton = "OK")
 {
     var box = new Microsoft.Phone.Controls.CustomMessageBox()
     {
         Caption = title,
         Message = message,
         LeftButtonContent = okButton,
         IsRightButtonEnabled = false
     };
     var complete = new TaskCompletionSource<bool>();
     box.Dismissed += (sender, args) => complete.TrySetResult(true);
     box.Show();
     return complete.Task;
 }
 public Task<bool> ConfirmAsync(string message, string title = "", string okButton = "OK", string cancelButton = "Cancel")
 {
     var box = new Microsoft.Phone.Controls.CustomMessageBox()
     {
         Caption = title,
         Message = message,
         LeftButtonContent = okButton,
         RightButtonContent = cancelButton
     };
     var complete = new TaskCompletionSource<bool>();
     box.Dismissed += (sender, args) => complete.TrySetResult(args.Result == CustomMessageBoxResult.LeftButton);
     box.Show();
     return complete.Task;
 }
Beispiel #7
0
        public Task AlertAsync(string message, string title = "", string okButton = "OK")
        {
            var box = new Microsoft.Phone.Controls.CustomMessageBox()
            {
                Caption              = title,
                Message              = message,
                LeftButtonContent    = okButton,
                IsRightButtonEnabled = false
            };
            var complete = new TaskCompletionSource <bool>();

            box.Dismissed += (sender, args) => complete.TrySetResult(true);
            box.Show();
            return(complete.Task);
        }
Beispiel #8
0
        public Task <bool> ConfirmAsync(string message, string title = "", string okButton = "OK", string cancelButton = "Cancel")
        {
            var box = new Microsoft.Phone.Controls.CustomMessageBox()
            {
                Caption            = title,
                Message            = message,
                LeftButtonContent  = okButton,
                RightButtonContent = cancelButton
            };
            var complete = new TaskCompletionSource <bool>();

            box.Dismissed += (sender, args) => complete.TrySetResult(args.Result == CustomMessageBoxResult.LeftButton);
            box.Show();
            return(complete.Task);
        }
Beispiel #9
0
        /// <summary>
        /// Creates CustomMessageBox with About content
        /// </summary>
        /// <returns>Grid</returns>
        public static CustomMessageBox GetAboutMessageBox()
        {
            XElement appInfo = XDocument.Load("WMAppManifest.xml")
                .Root.Element("App");

            string title = appInfo.Attribute("Title").Value;
            string version = appInfo.Attribute("Version").Value;
            string description = appInfo.Attribute("Description").Value;

            Grid grid = new Grid()
            {
                Margin = new Thickness(12, 0, 0, 0)
            };

            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());

            TextBlock txtBlockTitle = new TextBlock()
            {
                Text = title,
                FontSize = double.Parse(Application.Current.Resources["PhoneFontSizeLarge"].ToString())
            };

            TextBlock txtBlockMessage = new TextBlock()
            {
                Text = string.Format("\n{0}\nVersion: {1}",
                    description, version),
                FontSize = double.Parse(Application.Current.Resources["PhoneFontSizeMediumLarge"].ToString())
            };

            Grid.SetRow(txtBlockMessage, 1);
            grid.Children.Add(txtBlockTitle);
            grid.Children.Add(txtBlockMessage);

            CustomMessageBox msgBox = new CustomMessageBox()
            {
                Caption = AppResources.ApplicationBarAboutMenuItem,
                Content = grid,
                LeftButtonContent = "ok"
            };

            return msgBox;
        }
Beispiel #10
0
        public override Task Execute(object option)
        {
            var messageBox = new CustomMessageBox
            {
                Caption = Service.Current.Messages["Delete"],
                Message = Service.Current.Messages["AskForDeleteItems"],
                LeftButtonContent = Service.Current.Messages["Delete"],
                RightButtonContent = Service.Current.Messages["Cancel"]
            };

            var waiter = new AutoResetEvent(false);
            messageBox.Dismissed += async (s1, e1) =>
            {
                if (e1.Result == CustomMessageBoxResult.LeftButton)
                    await base.Execute(option);

                waiter.Set();
            };

            messageBox.Show();

            return Task.Factory.StartNew(() => waiter.WaitOne());
        }
Beispiel #11
0
		private async void check_click(object sender, RoutedEventArgs e)
		{
			bool isNetwork = NetworkInterface.GetIsNetworkAvailable();

			if (isNetwork)
			{
				try
				{
					WorldBuilding worldbuildings1 = await CustomPushpinWp8APIClient.GetWorldBuildings();
					if (worldbuildings1.buildings.Count > Helper.worldbuildings.buildings.Count)
					{
						CustomMessageBox messageBox = new CustomMessageBox()
						{
							Caption = "Buildings",
							Message = "New Buildings found. Do you want to download them?",
							LeftButtonContent = "yes",
							RightButtonContent = "no"
						};
						messageBox.Dismissed += (s1, e1) =>
						{
							switch (e1.Result)
							{
								case CustomMessageBoxResult.LeftButton:
									downloading.Visibility = Visibility.Visible;
									downloaded = true;
                                    downloadData();
									break;
								case CustomMessageBoxResult.RightButton:
									// Do something.
									break;
								case CustomMessageBoxResult.None:
									// Do something.
									break;
								default:
									break;
							}
						};

						messageBox.Show();
					}
					else
						MessageBox.Show("No new Buildings found!");
				}
				catch
				{
					MessageBox.Show("Can not check for update. Please check your connection and try again!");
				}
			}
			else
				MessageBox.Show("No internet connection found. Please check your internet connection and try again later!", "No Internet Connection", MessageBoxButton.OK);

		}
       public Task<InputResponse> InputAsync(string message, string placeholder = null, string title = null, string okButton = "OK",
            string cancelButton = "Cancel", string initialText = null)
        {
            var textBox = new PhoneTextBox { Hint = placeholder };

            var box = new Microsoft.Phone.Controls.CustomMessageBox()
            {
                Caption = title,
                Message = message,
                LeftButtonContent = okButton,
                RightButtonContent = cancelButton,
                Content = textBox
            };

            var response = new TaskCompletionSource<InputResponse>();
            box.Dismissed += (sender, args) => response.TrySetResult(new InputResponse()
            {
                Ok = args.Result == CustomMessageBoxResult.LeftButton,
                Text = textBox.Text
            });
            box.Show();
            return response.Task;
        }
        public Task<ConfirmThreeButtonsResponse> ConfirmThreeButtonsAsync(string message, string title = null, string positive = "Yes", string negative = "No", string neutral = "Maybe")
        {
            StackPanel contents = new StackPanel();
            contents.Orientation = Orientation.Vertical;
            var positiveButton = new Button() { Content = positive };
            var neutralButton = new Button() { Content = neutral };
            var negativeButton = new Button() { Content = negative };
            contents.Children.Add(positiveButton);
            contents.Children.Add(neutralButton);
            contents.Children.Add(negativeButton);

            var box = new Microsoft.Phone.Controls.CustomMessageBox()
            {
                Caption = title,
                Message = message,
                IsLeftButtonEnabled = false,
                IsRightButtonEnabled = false,
                Content = contents
            };

            var response = new TaskCompletionSource<ConfirmThreeButtonsResponse>();
            positiveButton.Click += (sender, args) =>
            {
                response.TrySetResult(ConfirmThreeButtonsResponse.Positive);
                box.Dismiss();
            };
            neutralButton.Click += (sender, args) =>
            {
                response.TrySetResult(ConfirmThreeButtonsResponse.Neutral);
                box.Dismiss();
            };
            negativeButton.Click += (sender, args) =>
            {
                response.TrySetResult(ConfirmThreeButtonsResponse.Negative);
                box.Dismiss();
            };
            box.Show();
            return response.Task;


        }
        /// <summary>
        /// Reveals the message box by inserting it into a popup and opening it.
        /// </summary>
        public void Show()
        {
            if (_popup != null)
            {
                if (_popup.IsOpen)
                {
                    return;
                }
            }

            LayoutUpdated += CustomMessageBox_LayoutUpdated;

            _frame = Application.Current.RootVisual as PhoneApplicationFrame;
            _page  = _frame.Content as PhoneApplicationPage;

            // Change the color of the system tray if necessary.
            if (SystemTray.IsVisible)
            {
                // Cache the original color of the system tray.
                _systemTrayColor = SystemTray.BackgroundColor;

                // Change the color of the system tray to match the message box.
                if (Background is SolidColorBrush)
                {
                    SystemTray.BackgroundColor = ((SolidColorBrush)Background).Color;
                }
                else
                {
                    SystemTray.BackgroundColor = (Color)Application.Current.Resources["PhoneChromeColor"];
                }
            }

            // Hide the application bar if necessary.
            if (_page.ApplicationBar != null)
            {
                // Cache the original visibility of the system tray.
                _hasApplicationBar = _page.ApplicationBar.IsVisible;

                // Hide it.
                if (_hasApplicationBar)
                {
                    _page.ApplicationBar.IsVisible = false;
                }
            }
            else
            {
                _hasApplicationBar = false;
            }

            // Dismiss the current message box if there is any.
            if (_currentInstance != null)
            {
                _mustRestore = false;

                CustomMessageBox target = _currentInstance.Target as CustomMessageBox;

                if (target != null)
                {
                    _systemTrayColor   = target._systemTrayColor;
                    _hasApplicationBar = target._hasApplicationBar;
                    target.Dismiss();
                }
            }

            _mustRestore = true;

            // Insert the overlay.
            Rectangle overlay         = new Rectangle();
            Color     backgroundColor = (Color)Application.Current.Resources["PhoneBackgroundColor"];

            overlay.Fill = new SolidColorBrush(Color.FromArgb(0x99, backgroundColor.R, backgroundColor.G, backgroundColor.B));
            _container   = new Grid();
            _container.Children.Add(overlay);

            // Insert the message box.
            _container.Children.Add(this);

            // Create and open the popup.
            _popup       = new Popup();
            _popup.Child = _container;
            SetSizeAndOffset();
            _popup.IsOpen    = true;
            _currentInstance = new WeakReference(this);

            // Attach event handlers.
            if (_page != null)
            {
                _page.BackKeyPress       += OnBackKeyPress;
                _page.OrientationChanged += OnOrientationChanged;
            }

            if (_frame != null)
            {
                _frame.Navigating += OnNavigating;
            }
        }