Example #1
0
 private void Cd_PrimaryButtonClick(Windows.UI.Xaml.Controls.ContentDialog sender, Windows.UI.Xaml.Controls.ContentDialogButtonClickEventArgs args)
 {
     if (Commands.Count > 0)
     {
         Commands[0].Invoked.Invoke(Commands[0]);
     }
 }
        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);
        }
Example #3
0
 private void ContentDialog_PrimaryButtonClick(Windows.UI.Xaml.Controls.ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     Values.ProgramSettings.Values["ControlMode " + OutNumber.ToString()] = ControlModeCombo.SelectedIndex.ToString();
     Values.ProgramSettings.Values["AutoMode " + OutNumber.ToString()]    = SensorModeCombo.SelectedIndex.ToString();
     Values.ProgramSettings.Values["AutoOn " + OutNumber.ToString()]      = SetPointSlider.Value.ToString();
     Values.ProgramSettings.Values["AutoTimeOut " + OutNumber.ToString()] = TimeOutSlider.Value.ToString();
     Values.ProgramSettings.Values["AutoTimeOn " + OutNumber.ToString()]  = OnTimePicker.Time.TotalSeconds.ToString();
     Values.ProgramSettings.Values["AutoTimeOff " + OutNumber.ToString()] = OffTimePicker.Time.TotalSeconds.ToString();
 }
Example #4
0
        private void ContentDialog_PrimaryButtonClick(Windows.UI.Xaml.Controls.ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            switch (Values.CalibrationDialog)
            {
            case "Step 1 of 3: Calibrate Dry":
                Values.CalibrationDelay  = 600;
                Values.CalibrationDialog = "Cal,dry";
                break;

            case "Step 2 of 3: Calibrate in 12,880 uS solution":
                Values.CalibrationDelay  = 600;
                Values.CalibrationDialog = "Cal,low,12880";
                break;

            case "Step 3 of 3: Calibrate in 80,000 uS solution":
                Values.CalibrationDelay  = 600;
                Values.CalibrationDialog = "Cal,high,80000";
                break;

            case "Step 1 of 1: Calibrate in 225 mV solution":
                Values.CalibrationDelay  = 900;
                Values.CalibrationDialog = "Cal,225";
                break;

            case "Step 1 of 3: Calibrate in 7.00 solution":
                Values.CalibrationDelay  = 900;
                Values.CalibrationDialog = "Cal,mid,7.00";
                break;

            case "Step 2 of 3: Calibrate in 4.00 solution":
                Values.CalibrationDelay  = 900;
                Values.CalibrationDialog = "Cal,low,4.00";
                break;

            case "Step 3 of 3: Calibrate in 10.00 solution":
                Values.CalibrationDelay  = 900;
                Values.CalibrationDialog = "Cal,high,10.00";
                break;

            case "Step 1 of 2: Calibrate at atmosphere":
                Values.CalibrationDelay  = 1300;
                Values.CalibrationDialog = "Cal";
                break;

            case "Step 2 of 2: Calibrate in 0 DO solution":
                Values.CalibrationDelay  = 1300;
                Values.CalibrationDialog = "Cal,0";
                break;

            case "Step 1 of 1: Calibrate in boiling water":
                Values.CalibrationDelay  = 600;
                Values.CalibrationDialog = "Cal,212.00";
                break;
            }
        }
Example #5
0
 private void ContentDialog_PrimaryButtonClick(Windows.UI.Xaml.Controls.ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     Values.ProgramSettings.Values["LightsOnTime"]       = (OnTimePicker.Time.TotalSeconds).ToString();
     Values.ProgramSettings.Values["LightsOffTime"]      = (OffTimePicker.Time.TotalSeconds).ToString();
     Values.ProgramSettings.Values["LightOutOneMax"]     = (CHOneSlider.Value / 100).ToString();
     Values.ProgramSettings.Values["LightOutTwoMax"]     = (CHTwoSlider.Value / 100).ToString();
     Values.ProgramSettings.Values["LightOutThreeMax"]   = (CHThreeSlider.Value / 100).ToString();
     Values.ProgramSettings.Values["LightOutFourMax"]    = (CHFourSlider.Value / 100).ToString();
     Values.ProgramSettings.Values["LightOutFiveMax"]    = (CHFiveSlider.Value / 100).ToString();
     Values.ProgramSettings.Values["LightOutNightLight"] = (CHNightLightSlider.Value / 100).ToString();
 }
Example #6
0
 private void ContentDialog_PrimaryButtonClick(Windows.UI.Xaml.Controls.ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     Values.FeedDuration = (int)FeedSlider.Value;
     Values.ProgramSettings.Values["FeedDuration"]    = Values.FeedDuration.ToString();
     Values.ProgramSettings.Values["OutputOneFeed"]   = OutOneButton.Background == defaultBackColor ? "0" : "1";
     Values.ProgramSettings.Values["OutputTwoFeed"]   = OutTwoButton.Background == defaultBackColor ? "0" : "1";
     Values.ProgramSettings.Values["OutputThreeFeed"] = OutThreeButton.Background == defaultBackColor ? "0" : "1";
     Values.ProgramSettings.Values["OutputFourFeed"]  = OutFourButton.Background == defaultBackColor ? "0" : "1";
     Values.ProgramSettings.Values["OutputFiveFeed"]  = OutFiveButton.Background == defaultBackColor ? "1" : "0";
     Values.ProgramSettings.Values["OutputSixFeed"]   = OutSixButton.Background == defaultBackColor ? "1" : "0";
     Values.ProgramSettings.Values["OutputSevenFeed"] = OutSevenButton.Background == defaultBackColor ? "1" : "0";
     Values.ProgramSettings.Values["OutputEightFeed"] = OutEightButton.Background == defaultBackColor ? "1" : "0";
 }
Example #7
0
        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();
        }
Example #8
0
        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.
        }
Example #9
0
        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);
            }
        }
Example #10
0
 private void ContentDialog_SecondaryButtonClick(Windows.UI.Xaml.Controls.ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
 }
Example #11
0
 private void Dialog_Closed(Windows.UI.Xaml.Controls.ContentDialog sender, Windows.UI.Xaml.Controls.ContentDialogClosedEventArgs args)
 {
     Dialog?.dismiss();
     SingleDialogSem.Release();
 }
Example #12
0
        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");
            }
        }
Example #13
0
        /// <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
        }
Example #14
0
        /// <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
        }
Example #15
0
 private void ContentDialog_PrimaryButtonClick(Windows.UI.Xaml.Controls.ContentDialog sender, ContentDialogButtonClickEventArgs args)
 {
     Values.ContentDialog = LabelTextBox.Text.ToString();
 }
Example #16
0
        /// <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
        }
Example #17
0
        /// <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
        }
Example #18
0
 private void Cd_SecondaryButtonClick(Windows.UI.Xaml.Controls.ContentDialog sender, Windows.UI.Xaml.Controls.ContentDialogButtonClickEventArgs args)
 {
     Commands[1].Invoked.Invoke(Commands[1]);
 }