/// <summary> /// Display a notification to the user with options. /// </summary> /// <param name="message"></param> /// <param name="title"></param> /// <param name="visualizerOptions"></param> /// <returns></returns> public Task <IUICommand> ShowAsync(string message, string title, MessageVisualizerOptions visualizerOptions) { // Cannot have nulls - throws exception. if (string.IsNullOrEmpty(message)) { message = string.Empty; } if (string.IsNullOrEmpty(title)) { title = string.Empty; } if (visualizerOptions == null) { visualizerOptions = new MessageVisualizerOptions(UICommand.Ok); } MessageDialog messageDialog = new MessageDialog(message, title) { DefaultCommandIndex = (uint)visualizerOptions.DefaultCommandIndex, CancelCommandIndex = (uint)visualizerOptions.CancelCommandIndex, }; foreach (var command in visualizerOptions.Commands) { messageDialog.Commands.Add(command); } return(messageDialog.ShowAsync().AsTask()); }
/// <summary> /// Display a notification to the user with options. /// </summary> /// <param name="message"></param> /// <param name="title"></param> /// <param name="visualizerOptions"></param> /// <returns></returns> public Task <IUICommand> ShowAsync(string message, string title, MessageVisualizerOptions visualizerOptions) { if (string.IsNullOrEmpty(message)) { message = string.Empty; } if (string.IsNullOrEmpty(title)) { title = string.Empty; } if (visualizerOptions == null) { visualizerOptions = new MessageVisualizerOptions(UICommand.Ok); } var tcs = new TaskCompletionSource <IUICommand>(); var alert = new AlertDialog.Builder(Application.Context) .SetTitle(title) .SetMessage(message) .SetItems(visualizerOptions.Commands.Select(c => c.Label).ToArray(), (s, e) => tcs.SetResult(visualizerOptions.Commands[e.Which])); alert.Create().Show(); return(tcs.Task); }
/// <summary> /// Display a notification to the user with options. /// </summary> /// <param name="message"></param> /// <param name="title"></param> /// <param name="visualizerOptions"></param> /// <returns></returns> public async Task <IUICommand> ShowAsync(string message, string title, MessageVisualizerOptions visualizerOptions) { // Cannot have nulls - throws exception. if (string.IsNullOrEmpty(message)) { message = string.Empty; } if (string.IsNullOrEmpty(title)) { title = string.Empty; } if (visualizerOptions == null) { visualizerOptions = new MessageVisualizerOptions(UICommand.Ok); } var messageDialog = new global::Windows.UI.Popups.MessageDialog(message, title) { DefaultCommandIndex = (uint)visualizerOptions.DefaultCommandIndex, CancelCommandIndex = (uint)visualizerOptions.CancelCommandIndex, }; foreach (var command in visualizerOptions.Commands) { messageDialog.Commands.Add(command.ToWindowsCommand()); } // Pull the original command back out. var result = await messageDialog.ShowAsync(); return(((UICommandExtensions.WindowsCommand)result).Command); }
/// <summary> /// Display a notification to the user with options. /// </summary> /// <param name="message"></param> /// <param name="title"></param> /// <param name="visualizerOptions"></param> /// <returns></returns> public async Task <IUICommand> ShowAsync(string message, string title, MessageVisualizerOptions visualizerOptions) { if (string.IsNullOrEmpty(message)) { message = string.Empty; } if (string.IsNullOrEmpty(title)) { title = string.Empty; } if (visualizerOptions == null) { visualizerOptions = new MessageVisualizerOptions(UICommand.Ok); } var alertDialog = new UIAlertView( title, message, null, visualizerOptions.Commands[0].Label, visualizerOptions.Commands.Skip(1).Select(c => c.Label).ToArray()); IUICommand selectedCommand = null; CancellationTokenSource cts = new CancellationTokenSource(); alertDialog.Dismissed += (sender, args) => { selectedCommand = visualizerOptions.Commands[(int)args.ButtonIndex]; cts.Cancel(); }; await Task.Delay(TimeSpan.MaxValue, cts.Token); return(selectedCommand); }
/// <summary> /// Display a notification to the user with options. /// </summary> /// <param name="message"></param> /// <param name="title"></param> /// <param name="visualizerOptions"></param> /// <returns></returns> public async Task <IUICommand> ShowAsync(string message, string title, MessageVisualizerOptions visualizerOptions) { if (string.IsNullOrEmpty(message)) { message = string.Empty; } if (string.IsNullOrEmpty(title)) { title = string.Empty; } if (visualizerOptions == null) { visualizerOptions = new MessageVisualizerOptions(UICommand.Ok); } var dialog = new MessageDialog(message, title); dialog.Commands.AddRange(visualizerOptions.Commands.Select(c => new Windows.UI.Popups.UICommand(c.Label, null, c.Id))); dialog.CancelCommandIndex = 0; var result = await dialog.ShowAsync(); return(visualizerOptions.Commands.Single(c => c.Id == result.Id && c.Label == result.Label)); }
public System.Threading.Tasks.Task <Windows.UI.Popups.IUICommand> ShowAsync(string message, string title, MessageVisualizerOptions visualizerOptions) { Page.ShowMessageAsync(message, title); return(null); }
public async Task <IUICommand> ShowAsync(string message, string title, MessageVisualizerOptions visualizerOptions) { if (visualizerOptions == null) { visualizerOptions = new MessageVisualizerOptions(UICommand.Ok); } var popup = new Window { WindowStartupLocation = WindowStartupLocation.CenterScreen, SizeToContent = SizeToContent.WidthAndHeight, Background = SystemColors.ControlLightBrush, Foreground = SystemColors.ControlTextBrush, Title = title, MinWidth = 200, MinHeight = 100, }; StackPanel rootPanel = new StackPanel(); TextBlock messageText = new TextBlock { Text = message, Margin = new Thickness(20), TextWrapping = TextWrapping.Wrap, MaxWidth = SystemParameters.PrimaryScreenWidth / 2, MaxHeight = SystemParameters.FullPrimaryScreenWidth / 2, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; rootPanel.Children.Add(messageText); var commands = visualizerOptions.Commands; if (commands.Count == 0) { commands = new[] { UICommand.Ok } } ; IUICommand finalCommand = null; WrapPanel buttonPanel = new WrapPanel() { Margin = new Thickness(10), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; for (int index = 0; index < commands.Count; index++) { var oneCommand = commands[index]; IUICommand command = oneCommand; Button commandButton = new Button { Content = command.Label, Tag = command, MinWidth = 75, Margin = new Thickness(5), Padding = new Thickness(10, 5, 10, 5), IsDefault = index == visualizerOptions.DefaultCommandIndex, IsCancel = index == visualizerOptions.CancelCommandIndex, }; commandButton.Click += (s, e) => { if (command.Invoked != null) { command.Invoked(); } finalCommand = ((Button)s).Tag as IUICommand; popup.DialogResult = !((Button)s).IsCancel; }; buttonPanel.Children.Add(commandButton); } rootPanel.Children.Add(buttonPanel); popup.Content = rootPanel; await Task.Run( () => { bool?rc = null; Application.Current.Dispatcher.Invoke( () => { rc = popup.ShowDialog(); }); }); return(finalCommand); } }
public IUICommand Show(string title, string message, MessageVisualizerOptions visualizerOptions) { return(Response); }