public async void Show(object dialogContent, IOKCancelViewModel viewModel) { var contentDialog = new Windows.UI.Xaml.Controls.ContentDialog { Content = dialogContent, PrimaryButtonText = "Ok", CloseButtonText = "Cancel", MinWidth = 1000, }; if (viewModel != null) { Console.WriteLine("hooking"); contentDialog.DataContext = viewModel; contentDialog.Closing += (sender, args) => { Console.WriteLine("Closing " + args.Result); if (args.Result == ContentDialogResult.Primary) { viewModel.OK(args); } }; } var res = await contentDialog.ShowAsync(ContentDialogPlacement.Popup); }
private async void ShowconDlg() { var conDlg = new Windows.UI.Xaml.Controls.ContentDialog { Title = "输入URL", PrimaryButtonText = "确定", SecondaryButtonText = "取消" }; conDlg.Content = txtbox; conDlg.PrimaryButtonClick += ConDlg_PrimaryButtonClick; await conDlg.ShowAsync(); }
public static async void SetupDialog(GetDialogInfo name) { var dialogCreate = new Windows.UI.Xaml.Controls.ContentDialog(); var commentCreate = new CommentCreate(); switch (name) { case 0: dialogCreate.Title = "Write your story of love here:"; dialogCreate.CloseButtonText = "Cancel"; dialogCreate.PrimaryButtonText = "Send"; dialogCreate.PrimaryButtonStyle = (Style)Application.Current.Resources["AccentButtonStyle"]; dialogCreate.SecondaryButtonText = "Save"; //dialogCreate.DefaultButton = ContentDialogButton.Primary; dialogCreate.Content = commentCreate; dialogCreate.Background = new SolidColorBrush(Colors.Black); if (!Generic.DeviceFamilyMatch(DeviceFamilyList.Mobile)) { dialogCreate.CloseButtonStyle = (Style)Application.Current.Resources["ButtonRevealStyle"]; dialogCreate.SecondaryButtonStyle = (Style)Application.Current.Resources["ButtonRevealStyle"]; dialogCreate.BorderBrush = (Brush)Application.Current.Resources["SystemControlBackgroundListMediumRevealBorderBrush"]; } break; case (GetDialogInfo)1: dialogCreate.Title = "Release Notes"; dialogCreate.CloseButtonText = "Okay"; dialogCreate.Content = new ReleaseNotes(); dialogCreate.Background = new SolidColorBrush(Colors.Black); //if (!Generic.DeviceFamilyMatch(DeviceFamilyList.Mobile)) //{ // dialogCreate.CloseButtonStyle = (Style)Application.Current.Resources["ButtonRevealStyle"]; // dialogCreate.BorderBrush = (Brush)Application.Current.Resources["SystemControlBackgroundListMediumRevealBorderBrush"]; //} break; } try { var loaded = await dialogCreate.ShowAsync(); if (loaded == ContentDialogResult.Secondary) { commentCreate.SavingDate(); } } catch (System.Runtime.InteropServices.COMException) { } // Nothing todo. }
public static async Task ShowAsync(Exception e) { string exceptionMessage = e.ToString(); var dialog = new Windows.UI.Xaml.Controls.ContentDialog() { Title = "Something went wrong", Content = exceptionMessage, IsPrimaryButtonEnabled = true, PrimaryButtonText = "Copy", CloseButtonText = "Ok" }; var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { var package = new DataPackage(); package.SetText(exceptionMessage); Clipboard.SetContent(package); } }
/// <summary> /// Shows a MessageDialog using a ContentDialog on desktop Windows where possible. /// </summary> /// <param name="md">The MessageDialog</param> /// <returns>The selected command.</returns> public static IAsyncOperation<IUICommand> ShowAsync2(this MessageDialog md) { #if WINDOWS_UWP if (md.Commands.Count < 3 && Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Desktop") { Windows.UI.Xaml.Controls.ContentDialog cd = new Windows.UI.Xaml.Controls.ContentDialog(); cd.Title = md.Title; cd.Content = md.Content; if (md.Commands.Count == 0) { cd.PrimaryButtonText = "Close"; } else { cd.PrimaryButtonText = md.Commands[0].Label; cd.PrimaryButtonClick += (cnd, c)=>{ if (md.Commands.Count > 0) { md.Commands[0].Invoked?.Invoke(md.Commands[0]); } }; if (md.Commands.Count > 1) { cd.SecondaryButtonText = md.Commands[1].Label; cd.SecondaryButtonClick += (cnd, c) => { md.Commands[1].Invoked?.Invoke(md.Commands[1]); }; } } return Task.Run<IUICommand>(async () => { ManualResetEvent mre = new ManualResetEvent(false); IUICommand command = null; await cd.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { ContentDialogResult dr = await cd.ShowAsync(); if (md.Commands.Count > 0) { switch (dr) { case ContentDialogResult.Primary: command = md.Commands[0]; break; case ContentDialogResult.Secondary: command = md.Commands[1]; break; } } }); mre.WaitOne(); return command; }).AsAsyncOperation<IUICommand>(); } else { return md.ShowAsync(); } #else return md.ShowAsync(); #endif }
/// <summary> /// Shows a MessageDialog using a ContentDialog on desktop Windows where possible. /// </summary> /// <param name="md">The MessageDialog</param> /// <returns>The selected command.</returns> public static IAsyncOperation <IUICommand> ShowAsync2(this MessageDialog md) { #if WINDOWS_UWP if (md.Commands.Count < 3 && Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Desktop") { Windows.UI.Xaml.Controls.ContentDialog cd = new Windows.UI.Xaml.Controls.ContentDialog(); cd.Title = md.Title; cd.Content = md.Content; if (md.Commands.Count == 0) { cd.PrimaryButtonText = "Close"; } else { cd.PrimaryButtonText = md.Commands[0].Label; cd.PrimaryButtonClick += (cnd, c) => { if (md.Commands.Count > 0) { md.Commands[0].Invoked?.Invoke(md.Commands[0]); } }; if (md.Commands.Count > 1) { cd.SecondaryButtonText = md.Commands[1].Label; cd.SecondaryButtonClick += (cnd, c) => { md.Commands[1].Invoked?.Invoke(md.Commands[1]); }; } } return(Task.Run <IUICommand>(async() => { ManualResetEvent mre = new ManualResetEvent(false); IUICommand command = null; await cd.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { ContentDialogResult dr = await cd.ShowAsync(); if (md.Commands.Count > 0) { switch (dr) { case ContentDialogResult.Primary: command = md.Commands[0]; break; case ContentDialogResult.Secondary: command = md.Commands[1]; break; } } }); mre.WaitOne(); return command; }).AsAsyncOperation <IUICommand>()); } else { return(md.ShowAsync()); } #else return(md.ShowAsync()); #endif }
/// <summary> /// Begins an asynchronous operation showing a dialog. /// </summary> /// <returns>An object that represents the asynchronous operation. /// For more on the async pattern, see Asynchronous programming in the Windows Runtime.</returns> /// <remarks>In some cases, such as when the dialog is closed by the system out of your control, your result can be an empty command. /// Returns either the command selected which destroyed the dialog, or an empty command. /// For example, a dialog hosted in a charms window will return an empty command if the charms window has been dismissed.</remarks> public Task<IUICommand> ShowAsync() { if (Commands.Count > MaxCommands) { throw new InvalidOperationException(); } #if __ANDROID__ Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity); Android.App.AlertDialog dialog = builder.Create(); dialog.SetTitle(Title); dialog.SetMessage(Content); if (Commands.Count == 0) { dialog.SetButton(-1, Resources.System.GetString(Android.Resource.String.Cancel), new EventHandler<Android.Content.DialogClickEventArgs>(Clicked)); } else { for (int i = 0; i < Commands.Count; i++) { dialog.SetButton(-1 - i, Commands[i].Label, new EventHandler<Android.Content.DialogClickEventArgs>(Clicked)); } } dialog.Show(); return Task.Run<IUICommand>(() => { _handle.WaitOne(); return _selectedCommand; }); #elif __IOS__ || __TVOS__ uac = UIAlertController.Create(Title, Content, UIAlertControllerStyle.Alert); if (Commands.Count == 0) { uac.AddAction(UIAlertAction.Create("Close", UIAlertActionStyle.Cancel | UIAlertActionStyle.Default, ActionClicked)); } else { for (int i = 0; i < Commands.Count; i++) { UIAlertAction action = UIAlertAction.Create(Commands[i].Label, CancelCommandIndex == i ? UIAlertActionStyle.Cancel : UIAlertActionStyle.Default, ActionClicked); uac.AddAction(action); } } UIViewController currentController = UIApplication.SharedApplication.KeyWindow.RootViewController; while (currentController.PresentedViewController != null) currentController = currentController.PresentedViewController; currentController.PresentViewController(uac, true, null); return Task.Run<IUICommand>(() => { _handle.WaitOne(); return _selectedCommand; }); #elif __MAC__ NSAlert alert = new NSAlert(); alert.AlertStyle = NSAlertStyle.Informational; alert.InformativeText = Content; alert.MessageText = Title; foreach(IUICommand command in Commands) { var button = alert.AddButton(command.Label); } alert.BeginSheetForResponse(NSApplication.SharedApplication.MainWindow, NSAlert_onEnded); return Task.Run<IUICommand>(() => { _handle.WaitOne(); return _selectedCommand; }); #elif WINDOWS_PHONE List<string> buttons = new List<string>(); foreach(IUICommand uic in this.Commands) { buttons.Add(uic.Label); } if (buttons.Count == 0) { buttons.Add("Close"); } MessageDialogAsyncOperation asyncOperation = new MessageDialogAsyncOperation(this); string contentText = Content; // trim message body to 255 chars if (contentText.Length > 255) { contentText = contentText.Substring(0, 255); } while(Microsoft.Xna.Framework.GamerServices.Guide.IsVisible) { Thread.Sleep(250); } Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox( string.IsNullOrEmpty(Title) ? " " : Title, contentText, buttons, (int)DefaultCommandIndex, // can choose which button has the focus Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.None, // can play sounds result => { int? returned = Microsoft.Xna.Framework.GamerServices.Guide.EndShowMessageBox(result); // process and fire the required handler if (returned.HasValue) { if (Commands.Count > returned.Value) { IUICommand theCommand = Commands[returned.Value]; asyncOperation.SetResults(theCommand); if (theCommand.Invoked != null) { theCommand.Invoked(theCommand); } } else { asyncOperation.SetResults(null); } } else { asyncOperation.SetResults(null); } }, null); return asyncOperation.AsTask<IUICommand>(); #elif WINDOWS_UWP if (Commands.Count < 3 && Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.UI.ApplicationSettings.ApplicationsSettingsContract", 1)) { Windows.UI.Xaml.Controls.ContentDialog cd = new Windows.UI.Xaml.Controls.ContentDialog(); cd.Title = Title; cd.Content = Content; if(Commands.Count == 0) { cd.PrimaryButtonText = "Close"; } else { cd.PrimaryButtonText = Commands[0].Label; cd.PrimaryButtonClick += Cd_PrimaryButtonClick; if(Commands.Count > 1) { cd.SecondaryButtonText = Commands[1].Label; cd.SecondaryButtonClick += Cd_SecondaryButtonClick; } } return Task.Run<IUICommand>(async () => { ManualResetEvent mre = new ManualResetEvent(false); IUICommand command = null; await cd.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => { ContentDialogResult dr = await cd.ShowAsync(); if (Commands.Count > 0) { switch (dr) { case ContentDialogResult.Primary: command = Commands[0]; if(Commands[0].Invoked != null) { Commands[0].Invoked.Invoke(Commands[0]); } break; case ContentDialogResult.Secondary: command = Commands[1]; if (Commands[1].Invoked != null) { Commands[1].Invoked.Invoke(Commands[1]); } break; } } }); mre.WaitOne(); return command; }); } else { Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(Content, Title); foreach (IUICommand command in Commands) { dialog.Commands.Add(new Windows.UI.Popups.UICommand(command.Label, (c)=> { command.Invoked(command); }, command.Id)); } return Task.Run<IUICommand>(async () => { Windows.UI.Popups.IUICommand command = await dialog.ShowAsync(); if (command != null) { int i = 0; foreach(Windows.UI.Popups.IUICommand c in dialog.Commands) { if(command == c) { break; } i++; } return Commands[i]; } return null; }); } #elif WIN32 return Task.Run<IUICommand>(() => { IUICommand cmd = ShowTaskDialog(); if (cmd != null) { cmd.Invoked?.Invoke(cmd); } return cmd; }); #else throw new PlatformNotSupportedException(); #endif }
/// <summary> /// Begins an asynchronous operation showing a dialog. /// </summary> /// <returns>An object that represents the asynchronous operation. /// For more on the async pattern, see Asynchronous programming in the Windows Runtime.</returns> /// <remarks>In some cases, such as when the dialog is closed by the system out of your control, your result can be an empty command. /// Returns either the command selected which destroyed the dialog, or an empty command. /// For example, a dialog hosted in a charms window will return an empty command if the charms window has been dismissed.</remarks> public Task <IUICommand> ShowAsync() { if (Commands.Count > MaxCommands) { throw new InvalidOperationException(); } #if __ANDROID__ Android.App.AlertDialog.Builder builder = new Android.App.AlertDialog.Builder(Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity); Android.App.AlertDialog dialog = builder.Create(); dialog.SetTitle(Title); dialog.SetMessage(Content); if (Commands.Count == 0) { dialog.SetButton(-1, Resources.System.GetString(Android.Resource.String.Cancel), new EventHandler <Android.Content.DialogClickEventArgs>(Clicked)); } else { for (int i = 0; i < Commands.Count; i++) { dialog.SetButton(-1 - i, Commands[i].Label, new EventHandler <Android.Content.DialogClickEventArgs>(Clicked)); } } dialog.Show(); return(Task.Run <IUICommand>(() => { _handle.WaitOne(); return _selectedCommand; })); #elif __IOS__ || __TVOS__ uac = UIAlertController.Create(Title, Content, UIAlertControllerStyle.Alert); if (Commands.Count == 0) { uac.AddAction(UIAlertAction.Create("Close", UIAlertActionStyle.Cancel | UIAlertActionStyle.Default, ActionClicked)); } else { for (int i = 0; i < Commands.Count; i++) { UIAlertAction action = UIAlertAction.Create(Commands[i].Label, CancelCommandIndex == i ? UIAlertActionStyle.Cancel : UIAlertActionStyle.Default, ActionClicked); uac.AddAction(action); } } UIViewController currentController = UIApplication.SharedApplication.KeyWindow.RootViewController; while (currentController.PresentedViewController != null) { currentController = currentController.PresentedViewController; } currentController.PresentViewController(uac, true, null); return(Task.Run <IUICommand>(() => { _handle.WaitOne(); return _selectedCommand; })); #elif __MAC__ NSAlert alert = new NSAlert(); alert.AlertStyle = NSAlertStyle.Informational; alert.InformativeText = Content; alert.MessageText = Title; foreach (IUICommand command in Commands) { var button = alert.AddButton(command.Label); } alert.BeginSheetForResponse(NSApplication.SharedApplication.MainWindow, NSAlert_onEnded); return(Task.Run <IUICommand>(() => { _handle.WaitOne(); return _selectedCommand; })); #elif WINDOWS_PHONE List <string> buttons = new List <string>(); foreach (IUICommand uic in Commands) { buttons.Add(uic.Label); } if (buttons.Count == 0) { buttons.Add("Close"); } MessageDialogAsyncOperation asyncOperation = new MessageDialogAsyncOperation(this); string contentText = Content; // trim message body to 255 chars if (contentText.Length > 255) { contentText = contentText.Substring(0, 255); } while (Microsoft.Xna.Framework.GamerServices.Guide.IsVisible) { Thread.Sleep(100); } Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox( string.IsNullOrEmpty(Title) ? " " : Title, contentText, buttons, DefaultCommandIndex == uint.MaxValue ? 0 : (int)DefaultCommandIndex, // can choose which button has the focus Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.None, // can play sounds result => { int?returned = Microsoft.Xna.Framework.GamerServices.Guide.EndShowMessageBox(result); // process and fire the required handler if (returned.HasValue) { if (Commands.Count > returned.Value) { IUICommand theCommand = Commands[returned.Value]; asyncOperation.SetResults(theCommand); if (theCommand.Invoked != null) { theCommand.Invoked(theCommand); } } else { asyncOperation.SetResults(null); } } else { asyncOperation.SetResults(null); } }, null); return(asyncOperation.AsTask <IUICommand>()); #elif WINDOWS_UWP if (Commands.Count < 3 && Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.UI.ApplicationSettings.ApplicationsSettingsContract", 1)) { Windows.UI.Xaml.Controls.ContentDialog cd = new Windows.UI.Xaml.Controls.ContentDialog(); cd.Title = Title; cd.Content = Content; if (Commands.Count == 0) { cd.PrimaryButtonText = "Close"; } else { cd.PrimaryButtonText = Commands[0].Label; cd.PrimaryButtonClick += Cd_PrimaryButtonClick; if (Commands.Count > 1) { cd.SecondaryButtonText = Commands[1].Label; cd.SecondaryButtonClick += Cd_SecondaryButtonClick; } } return(Task.Run <IUICommand>(async() => { ManualResetEvent mre = new ManualResetEvent(false); IUICommand command = null; await cd.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { ContentDialogResult dr = await cd.ShowAsync(); if (Commands.Count > 0) { switch (dr) { case ContentDialogResult.Primary: command = Commands[0]; if (Commands[0].Invoked != null) { Commands[0].Invoked.Invoke(Commands[0]); } break; case ContentDialogResult.Secondary: command = Commands[1]; if (Commands[1].Invoked != null) { Commands[1].Invoked.Invoke(Commands[1]); } break; } } }); mre.WaitOne(); return command; })); } else { Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog(Content, Title); foreach (IUICommand command in Commands) { dialog.Commands.Add(new Windows.UI.Popups.UICommand(command.Label, (c) => { command.Invoked(command); }, command.Id)); } return(Task.Run <IUICommand>(async() => { Windows.UI.Popups.IUICommand command = await dialog.ShowAsync(); if (command != null) { int i = 0; foreach (Windows.UI.Popups.IUICommand c in dialog.Commands) { if (command == c) { break; } i++; } return Commands[i]; } return null; })); } #elif WIN32 return(Task.Run <IUICommand>(() => { IUICommand cmd = ShowTaskDialog(); if (cmd != null) { cmd.Invoked?.Invoke(cmd); } return cmd; })); #else throw new PlatformNotSupportedException(); #endif }
private async void AppBarButton_Click(object sender, RoutedEventArgs e) { try { FolderPicker picker = new FolderPicker() { SuggestedStartLocation = PickerLocationId.ComputerFolder }; picker.FileTypeFilter.Add(".png"); picker.FileTypeFilter.Add(".jpeg"); picker.FileTypeFilter.Add(".jpg"); StorageFolder folder = await picker.PickSingleFolderAsync(); Windows.Storage.StorageFolder storageFolder = folder; var files = await folder.GetFilesAsync(); await ApplicationData.Current.LocalFolder.CreateFolderAsync("ImagesFolder", CreationCollisionOption.ReplaceExisting); foreach (var file in files) { StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; string folderName = System.IO.Path.GetFileNameWithoutExtension(file.Name); //folder name with filename ////await ApplicationData.Current.LocalFolder.CreateFolderAsync("Data");//need to change the folder name with filename testFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("ImagesFolder", CreationCollisionOption.OpenIfExists); ////StorageFolder newFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists); //StorageFolder newFolder = await testFolder.CreateFolderAsync(folderName, CreationCollisionOption.OpenIfExists); //string desiredName = file.Name; ////should copy it to subfolder and raise alert if already exist ////StorageFile newFile = await localFolder.CreateFileAsync(desiredName, CreationCollisionOption.FailIfExists); try { await file.CopyAsync(testFolder, file.Name, NameCollisionOption.FailIfExists); } catch (Exception exp) { //show here messagebox that is exists Windows.UI.Xaml.Controls.ContentDialog replacePromptDialog = new Windows.UI.Xaml.Controls.ContentDialog() { Title = "File exists in the new location", Content = "Do you want to replace the old file with the new file?", CloseButtonText = "Keep the old one", PrimaryButtonText = "Replace with new one" }; Windows.UI.Xaml.Controls.ContentDialogResult result = await replacePromptDialog.ShowAsync(); if (result == Windows.UI.Xaml.Controls.ContentDialogResult.Primary) { // await file.CopyAsync(newFolder, desiredName, NameCollisionOption.ReplaceExisting); } } } Process(testFolder); refreshButton.IsEnabled = true; stopFlag = false; } catch (Exception exx) { Debug.WriteLine("Exception"); } }