コード例 #1
0
ファイル: Program.cs プロジェクト: ExpLife0011/JuusanKoubou
        static void buttonEnableDisable_Click(object sender, EventArgs e)
        {
            // Enable/disable sample
            TaskDialog tdEnableDisable = new TaskDialog();

            tdEnableDisable.Cancelable      = true;
            tdEnableDisable.Caption         = "Enable/Disable Sample";
            tdEnableDisable.InstructionText = "Click on the buttons to enable or disable the radiobutton.";

            enableButton         = new TaskDialogButton("enableButton", "Enable");
            enableButton.Default = true;
            enableButton.Click  += new EventHandler(enableButton_Click);

            disableButton        = new TaskDialogButton("disableButton", "Disable");
            disableButton.Click += new EventHandler(disableButton_Click);

            enableDisableRadioButton         = new TaskDialogRadioButton("enableDisableRadioButton", "Sample Radio button");
            enableDisableRadioButton.Enabled = false;

            tdEnableDisable.Controls.Add(enableDisableRadioButton);
            tdEnableDisable.Controls.Add(enableButton);
            tdEnableDisable.Controls.Add(disableButton);

            TaskDialogResult tdr = tdEnableDisable.Show();

            enableDisableRadioButton = null;
            enableButton.Click      -= new EventHandler(enableButton_Click);
            disableButton.Click     -= new EventHandler(disableButton_Click);
            enableButton             = null;
            disableButton            = null;
        }
コード例 #2
0
 private TaskDialogResult(TaskDialogButtonBase selectedButton, TaskDialogRadioButton selectedRadioButton,
                          bool verificationChecked)
 {
     this.SelectedButton      = selectedButton;
     this.SelectedRadioButton = selectedRadioButton;
     this.VerificationChecked = verificationChecked;
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: ExpLife0011/JuusanKoubou
        static void iconsRadioButton_Click(object sender, EventArgs e)
        {
            TaskDialogRadioButton radioButton = sender as TaskDialogRadioButton;

            if (radioButton != null && currentTaskDialog != null)
            {
                switch (radioButton.Name)
                {
                case "radioNone":
                    currentTaskDialog.Icon = currentTaskDialog.FooterIcon = TaskDialogStandardIcon.None;
                    break;

                case "radioError":
                    currentTaskDialog.Icon = currentTaskDialog.FooterIcon = TaskDialogStandardIcon.Error;
                    break;

                case "radioWarning":
                    currentTaskDialog.Icon = currentTaskDialog.FooterIcon = TaskDialogStandardIcon.Warning;
                    break;

                case "radioInformation":
                    currentTaskDialog.Icon = currentTaskDialog.FooterIcon = TaskDialogStandardIcon.Information;
                    break;

                case "radioShield":
                    currentTaskDialog.Icon = currentTaskDialog.FooterIcon = TaskDialogStandardIcon.Shield;
                    break;
                }
            }
        }
コード例 #4
0
        /// <summary>
        ///     This is the event that happens when out form is closing.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                Log("Application exit!");
                var parser         = new FileIniDataParser();
                var iniD           = parser.ReadFile(SettingsPath);
                var showexitdialog = ToBoolean(int.Parse(iniD["DIALOG_PREFERENCES"]["exit_dialog"]));
                if (showexitdialog)
                {
                    #region Check for the dont show again

                    var td = new TaskDialog
                    {
                        WindowTitle = @"Warning",
                        Content     = @"Are you sure you would like to exit?"
                    };
                    td.Buttons.Add(new TaskDialogButton
                    {
                        ButtonType = ButtonType.No
                    });
                    td.Buttons.Add(new TaskDialogButton
                    {
                        ButtonType = ButtonType.Yes,
                        Default    = true
                    });
                    var checkbox = new TaskDialogRadioButton
                    {
                        Text    = @"Never show this again!",
                        Checked = false
                    };
                    td.RadioButtons.Add(checkbox);
                    if (td.ShowDialog().ButtonType == ButtonType.No)
                    {
                        e.Cancel = true;
                        Log("Exit cancelled!");
                    }
                    if (td.RadioButtons[0].Checked)
                    {
                        iniD["DIALOG_PREFERENCES"]["exit_dialog"] = "0";
                    }

                    #endregion
                }
                parser.WriteFile(SettingsPath, iniD);
            }
            catch (Exception ex)
            {
                Log("Terrible error happened at Close!");
                Log(ex.Message + " => " + ex.Source);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: ExpLife0011/JuusanKoubou
        private static void buttonIcons_Click(object sender, EventArgs e)
        {
            // Show icons on the taskdialog

            TaskDialog tdIcons = new TaskDialog();

            currentTaskDialog  = tdIcons;
            tdIcons.Cancelable = true;

            tdIcons.Caption         = "Icons Sample";
            tdIcons.InstructionText = "Main Instructions";
            tdIcons.FooterText      = "Footer Text";

            TaskDialogRadioButton radioNone = new TaskDialogRadioButton("radioNone", "None");

            radioNone.Default = true; // default is no icons
            radioNone.Click  += new EventHandler(iconsRadioButton_Click);

            TaskDialogRadioButton radioError = new TaskDialogRadioButton("radioError", "Error");

            radioError.Click += new EventHandler(iconsRadioButton_Click);

            TaskDialogRadioButton radioWarning = new TaskDialogRadioButton("radioWarning", "Warning");

            radioWarning.Click += new EventHandler(iconsRadioButton_Click);

            TaskDialogRadioButton radioInformation = new TaskDialogRadioButton("radioInformation", "Information");

            radioInformation.Click += new EventHandler(iconsRadioButton_Click);

            TaskDialogRadioButton radioShield = new TaskDialogRadioButton("radioShield", "Shield");

            radioShield.Click += new EventHandler(iconsRadioButton_Click);

            tdIcons.Controls.Add(radioNone);
            tdIcons.Controls.Add(radioError);
            tdIcons.Controls.Add(radioWarning);
            tdIcons.Controls.Add(radioInformation);
            tdIcons.Controls.Add(radioShield);

            tdIcons.Show();

            currentTaskDialog = null;
        }
コード例 #6
0
        /// <summary>
        ///     タスクダイアログを表示します。
        /// </summary>
        /// <param name="parentWindowHandle">親ウィンドウのハンドル。</param>
        public TaskDialogResult ShowDialog(IntPtr parentWindowHandle)
        {
            this.DialogShowStates = DialogShowStates.Showing;

            var config = CreateConfig(parentWindowHandle);

            int  selectedButtonId;
            int  selectedRadioButtonId;
            bool verificationChecked;

            TaskDialogNativeMethods.TaskDialogIndirect(
                config,
                out selectedButtonId,
                out selectedRadioButtonId,
                out verificationChecked);

            this.DialogShowStates = DialogShowStates.Closed;

            // Result
            TaskDialogButtonBase selectedButton = null;

            if (this.CustomButtons != null)
            {
                selectedButton = this.CustomButtons.FirstOrDefault(x => x.Id == selectedButtonId);
            }
            else if (this.CommandLinks != null)
            {
                selectedButton = this.CommandLinks.FirstOrDefault(x => x.Id == selectedButtonId);
            }

            TaskDialogRadioButton selectedRadioButton = null;

            if (this.RadioButtons != null)
            {
                selectedRadioButton = this.RadioButtons.FirstOrDefault(x => x.Id == selectedRadioButtonId);
            }

            return(TaskDialogResult.Create(selectedButton, selectedRadioButton, verificationChecked));
        }
コード例 #7
0
        private void OnComplexTaskDialog(object sender, RoutedEventArgs e)
        {
            var firstRadioButton  = new TaskDialogRadioButton("Radio1", "One");
            var secondRadioButton = new TaskDialogRadioButton("Radio1", "Two");
            var commandLink       = new TaskDialogCommandLink("Lonk1", "Information", "Sample command link");
            var progressBar       = new TaskDialogProgressBar("progress")
            {
                State = TaskDialogProgressBarState.Marquee
            };

            var taskDialog = new TaskDialog
            {
                Caption         = "Title",
                InstructionText = "Sample task dialog",
                StandardButtons = TaskDialogStandardButtons.Ok
            };

            taskDialog.Controls.Add(firstRadioButton);
            taskDialog.Controls.Add(secondRadioButton);
            taskDialog.Controls.Add(commandLink);
            taskDialog.Controls.Add(progressBar);

            taskDialog.Show();
        }
コード例 #8
0
 internal void SetRadioButtonEnabled(TaskDialogRadioButton button, bool enabled)
 {
     this.TaskDialogInternal.SetRadioButtonEnabled(button, enabled);
 }
コード例 #9
0
        public static void ShowUploadDialog(string DisplayFileName, Action LocalhostrCallback,
                                            Action LocalWebHostCallback, Action DropboxCallback, Action CancelCallback, IntPtr owner)
        {
            var success = false;

            TaskDialog confirm = new TaskDialog();

            confirm.FooterText      = "Read the <a href=\"http://localhostr.com/tos\">terms of service</a> for localhostr.com.  Your files are not in a public listing, but anyone knowing the URL may access them directly.  You are never able to delete uploaded content.";
            confirm.Cancelable      = true;
            confirm.Caption         = "Options for accessing your content";
            confirm.InstructionText = "How would you like to transfer " + DisplayFileName + " to your phone?";

            confirm.HyperlinksEnabled = true;
            confirm.HyperlinkClick   += (s, e) => System.Diagnostics.Process.Start("http://localhostr.com/tos");
            confirm.StandardButtons   = TaskDialogStandardButtons.Cancel;

            TaskDialogCommandLink localhostr = new TaskDialogCommandLink();

            localhostr.Text        = "Upload to localhostr.com";
            localhostr.Instruction = "Files are accessible over WiFi and 3G, but may not be secure.  Files are uploaded to the internet.";
            localhostr.Click      += (s, e) =>
            {
                success = true;
                confirm.Close();
                LocalhostrCallback();
            };
            confirm.Controls.Add(localhostr);

            TaskDialogCommandLink localserver = new TaskDialogCommandLink();

            localserver.Default     = true;
            localserver.Text        = "Host directly on my PC";
            localserver.Enabled     = Program.LocalFileStorage != null;
            localserver.Instruction = "Files are accessible at high speed, only over WiFi, but never transferred over the internet.  Files will not be copied, so if the file is removed from your computer, it will not be accessible to the phone.";
            localserver.Click      += (s, e) =>
            {
                success = true;
                confirm.Close();
                LocalWebHostCallback();
            };
            confirm.Controls.Add(localserver);

            TaskDialogCommandLink dropbox = new TaskDialogCommandLink();

            dropbox.Text        = "Host using my Dropbox account";
            dropbox.Instruction = "Files are accessible over WiFi and 3G, and are under your control.  Files are copied to your Dropbox Public folder.";
            dropbox.Click      += (s, e) =>
            {
                success = true;
                confirm.Close();
                DropboxCallback();
            };
            confirm.Controls.Add(dropbox);

            TaskDialogRadioButton askEachTime = new TaskDialogRadioButton();

            askEachTime.Default = Settings.Get("AskEachTime", true);
            askEachTime.Text    = "Ask me how to transfer files each time";
            askEachTime.Click  += (_, __) =>
            {
                Settings.Set("AskEachTime", true);
            };
            confirm.Controls.Add(askEachTime);
            TaskDialogRadioButton dontAsk = new TaskDialogRadioButton();

            dontAsk.Default = false == Settings.Get("AskEachTime", true);
            dontAsk.Text    = "Always use the option I select below";
            dontAsk.Click  += (_, __) =>
            {
                Settings.Set("AskEachTime", false);
            };
            confirm.Controls.Add(dontAsk);

            confirm.Closing += (s, e) =>
            {
                // this is always returning Cancel even if CommandLink is clicked
                if (e.TaskDialogResult == TaskDialogResult.Cancel && !success)
                {
                    CancelCallback();
                }
            };

            var t = new Thread(() =>
            {
                int x = 0;

                while (x < 25)
                {
                    if (confirm.Handle != IntPtr.Zero)
                    {
                        Trace.WriteLine("Handle: " + confirm.Handle);
                        Thread.Sleep(200);
                        BringWindowToTop(confirm.Handle);
                        return;
                    }
                    Thread.Sleep(50);
                    x++;
                }
            });

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            Trace.WriteLine("UPloader Handle: " + confirm.Handle);
            confirm.OwnerWindowHandle = owner;
            confirm.Show();
        }
コード例 #10
0
 internal static TaskDialogResult Create(TaskDialogButtonBase selectedButton, TaskDialogRadioButton selectedRadioButton,
                                         bool verificationChecked)
 {
     return(new TaskDialogResult(selectedButton, selectedRadioButton, verificationChecked));
 }
コード例 #11
0
 public void SetRadioButtonEnabled(TaskDialogRadioButton control, bool enabled)
 {
     this.Commands.EnableRadioButtonCommand(control.Id, enabled);
 }
コード例 #12
0
ファイル: Program.cs プロジェクト: kpreisser/TaskDialog
        private static void ShowTaskDialogExample()
        {
            var dialogPage = new TaskDialogPage()
            {
                Title       = "Example 1",
                Instruction = "Hello Task Dialog!   👍",
                Text        = "Hi, this is <A HREF=\"link1\">the Content</A>.\nBlah blah blah…",
                Icon        = TaskDialogStandardIcon.SecuritySuccessGreenBar,

                Footer =
                {
                    Text = "This is the <A HREF=\"link2\">footer</A>.",
                    Icon = TaskDialogStandardIcon.Warning,
                },

                Expander =
                {
                    Text             = "Expanded Information!",
                    ExpandFooterArea = true
                },

                ProgressBar = new TaskDialogProgressBar(),

                CustomButtonStyle = TaskDialogCustomButtonStyle.CommandLinks,
                EnableHyperlinks  = true,
                AllowCancel       = true,
                CanBeMinimized    = true,
                SizeToContent     = true,
            };

            dialogPage.Created += (s, e) =>
            {
                Console.WriteLine("Main Contents created!");
            };
            dialogPage.Destroyed += (s, e) =>
            {
                Console.WriteLine("Main Contents destroyed!");
            };

            dialogPage.Expander.ExpandedChanged += (s, e) =>
            {
                Console.WriteLine("Expander Expanded Changed: " + dialogPage.Expander.Expanded);
            };

            var dialog = new TaskDialog(dialogPage);

            dialog.Opened += (s, e) =>
            {
                Console.WriteLine("Dialog opened!");
            };
            dialog.Shown += (s, e) =>
            {
                Console.WriteLine("Dialog shown!");
            };
            dialog.Closing += (s, e) =>
            {
                Console.WriteLine("Dialog closing!");
            };
            dialog.Closed += (s, e) =>
            {
                Console.WriteLine("Dialog closed!");
            };
            //dialog.Activated += (s, e) =>
            //{
            //    Console.WriteLine("Dialog activated!");
            //};
            //dialog.Deactivated += (s, e) =>
            //{
            //    Console.WriteLine("Dialog deactivated!");
            //};

            dialogPage.ProgressBar.Value = 1;

            TaskDialogStandardButton buttonYes = dialogPage.StandardButtons.Add(TaskDialogResult.Yes);

            buttonYes.Enabled = false;
            TaskDialogStandardButton buttonNo = dialogPage.StandardButtons.Add(TaskDialogResult.No);

            // Add a hidden "Cancel" button so that we can get notified when the user
            // closes the dialog through the window's X button or with ESC (and could
            // cancel the close operation).
            TaskDialogStandardButton buttonCancelHidden = dialogPage.StandardButtons.Add(TaskDialogResult.Cancel);

            buttonCancelHidden.Visible = false;
            buttonCancelHidden.Click  += (s, e) =>
            {
                Console.WriteLine("Cancel clicked!");
            };

            long timerCount      = 2;
            var  dialogPageTimer = null as Timer;

            dialogPage.Created += (s, e) =>
            {
                dialogPageTimer = new Timer()
                {
                    Enabled  = true,
                    Interval = 200
                };
                dialogPageTimer.Tick += (s2, e2) =>
                {
                    // Update the progress bar if value <= 35.
                    if (timerCount <= 35)
                    {
                        dialogPage.ProgressBar.Value = (int)timerCount;
                    }
                    else if (timerCount == 36)
                    {
                        dialogPage.ProgressBar.State = TaskDialogProgressBarState.Paused;
                    }

                    timerCount++;
                };
            };
            dialogPage.Destroyed += (s, e) =>
            {
                dialogPageTimer.Dispose();
                dialogPageTimer = null;
            };

            dialogPage.HyperlinkClicked += (s, e) =>
            {
                Console.WriteLine("Hyperlink clicked!");
                TaskDialog.Show(dialog, "Clicked Hyperlink: " + e.Hyperlink, icon: TaskDialogStandardIcon.Information);
            };

            // Create custom buttons that are shown as command links.
            TaskDialogCustomButton button1 = dialogPage.CustomButtons.Add("Change Icon + Enable Buttons  ✔");
            TaskDialogCustomButton button2 = dialogPage.CustomButtons.Add("Disabled Button 🎵🎶", "After enabling, can show a new dialog.");
            TaskDialogCustomButton button3 = dialogPage.CustomButtons.Add("Some Admin Action…", "Navigates to a new dialog page.");

            button3.ElevationRequired = true;

            TaskDialogStandardIcon nextIcon = TaskDialogStandardIcon.SecuritySuccessGreenBar;

            button1.Click += (s, e) =>
            {
                Console.WriteLine("Button1 clicked!");

                // Don't close the dialog.
                e.CancelClose = true;

                nextIcon++;

                // Set the icon and the content.
                dialogPage.Icon        = nextIcon;
                dialogPage.Instruction = "Icon: " + nextIcon;

                // Enable the "Yes" button and the 3rd button when the checkbox is set.
                buttonYes.Enabled = true;
                button2.Enabled   = true;
            };

            button2.Enabled = false;
            button2.Click  += (s, e) =>
            {
                Console.WriteLine("Button2 clicked!");

                // Don't close the main dialog.
                e.CancelClose = true;

                // Show a new Taskdialog that shows an incrementing number.
                var newPage = new TaskDialogPage()
                {
                    Text = "This is a new non-modal dialog!",
                    Icon = TaskDialogStandardIcon.Information,
                };

                TaskDialogStandardButton buttonClose    = newPage.StandardButtons.Add(TaskDialogResult.Close);
                TaskDialogStandardButton buttonContinue = newPage.StandardButtons.Add(TaskDialogResult.Continue);

                int number = 0;
                void UpdateNumberText(bool callUpdate = true)
                {
                    // Update the instruction with the new number.
                    newPage.Instruction = "Hi there!  Number: " + number.ToString();
                }

                UpdateNumberText(false);

                var newPageTimer = null as Timer;
                newPage.Created += (s2, e2) =>
                {
                    newPageTimer = new Timer()
                    {
                        Enabled  = true,
                        Interval = 200
                    };
                    newPageTimer.Tick += (s3, e3) =>
                    {
                        number++;
                        UpdateNumberText();
                    };
                };
                newPage.Destroyed += (s2, e2) =>
                {
                    newPageTimer.Dispose();
                    newPageTimer = null;
                };

                buttonContinue.Click += (s2, e2) =>
                {
                    Console.WriteLine("New dialog - Continue Button clicked");

                    e2.CancelClose = true;
                    number        += 1000;
                    UpdateNumberText();
                };

                var innerDialog = new TaskDialog(newPage);
                TaskDialogButton innerResult = innerDialog.Show();
                Console.WriteLine("Result of new dialog: " + innerResult);
            };

            button3.Click += (s, e) =>
            {
                Console.WriteLine("Button3 clicked!");

                // Don't close the dialog from the button click.
                e.CancelClose = true;

                // Create a new contents instance to which we will navigate the dialog.
                var newContents = new TaskDialogPage()
                {
                    Instruction   = "Page 2",
                    Text          = "Welcome to the second page!",
                    Icon          = TaskDialogStandardIcon.SecurityShieldBlueBar,
                    SizeToContent = true,

                    CheckBox =
                    {
                        Text = "I think I agree…"
                    },
                    ProgressBar =
                    {
                        State = TaskDialogProgressBarState.Marquee
                    }
                };
                newContents.Created += (s2, e2) =>
                {
                    Console.WriteLine("New Contents created!");

                    // Set a new icon after navigating the dialog. This allows us to show the
                    // yellow bar from the "SecurityWarningBar" icon with a different icon.
                    newContents.Icon = TaskDialogStandardIcon.Warning;
                };
                newContents.Destroyed += (s2, e2) =>
                {
                    Console.WriteLine("New Contents destroyed!");
                };

                TaskDialogStandardButton buttonCancel = newContents.StandardButtons.Add(TaskDialogResult.Cancel);
                buttonCancel.Enabled           = false;
                buttonCancel.ElevationRequired = true;

                // Create a custom button that will be shown as regular button.
                TaskDialogCustomButton customButton = newContents.CustomButtons.Add("My Button :)");

                // Add radio buttons.
                TaskDialogRadioButton radioButton1 = newContents.RadioButtons.Add("My Radio Button 1");
                TaskDialogRadioButton radioButton2 = newContents.RadioButtons.Add("My Radio Button 2");
                radioButton2.Checked = true;

                radioButton1.CheckedChanged += (s2, e2) => Console.WriteLine(
                    $"Radio Button 1 CheckedChanged: RB1={radioButton1.Checked}, RB2={radioButton2.Checked}");
                radioButton2.CheckedChanged += (s2, e2) => Console.WriteLine(
                    $"Radio Button 2 CheckedChanged: RB1={radioButton1.Checked}, RB2={radioButton2.Checked}");

                newContents.CheckBox.CheckedChanged += (s2, e2) =>
                {
                    Console.WriteLine("Checkbox CheckedChanged: " + newContents.CheckBox.Checked);

                    buttonCancel.Enabled = newContents.CheckBox.Checked;
                };

                // Now navigate the dialog.
                dialog.Page = newContents;
            };

            TaskDialogButton result = dialog.Show();

            Console.WriteLine("Result of main dialog: " + result);
        }
コード例 #13
0
        /// <summary>
        /// The Vm_DeleteZipFileRequested.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_DeleteZipFileRequested(object sender, EventArgs e)
        {
            var a     = Assembly.GetExecutingAssembly();
            var st    = a.GetManifestResourceStream("PluginManager.Wpf.Resources.qmark.ico");
            var qmark = new Icon(st);

            st.Dispose();

            var win = new TaskDialog()
            {
                WindowTitle    = "Delete Requested",
                MainIcon       = TaskDialogIcon.Custom,
                CustomMainIcon = qmark
            };

            var rb1 = new TaskDialogRadioButton()
            {
                Text = "Only delete the zip file."
            };
            var rb2 = new TaskDialogRadioButton()
            {
                Text = "Only delete the database record."
            };
            var rb3 = new TaskDialogRadioButton()
            {
                Text = "Delete both record and file.", Checked = true
            };
            var bt1 = new TaskDialogButton(ButtonType.Cancel);
            var bt2 = new TaskDialogButton(ButtonType.Ok);

            win.RadioButtons.Add(rb1);
            win.RadioButtons.Add(rb2);
            win.RadioButtons.Add(rb3);
            win.Buttons.Add(bt1);
            win.Buttons.Add(bt2);
            win.Content = "What do you want to delete?";

            var result = win.ShowDialog();

            qmark.Dispose();
            win.Dispose();
            rb1.Dispose();
            rb2.Dispose();
            rb3.Dispose();
            bt1.Dispose();
            bt2.Dispose();

            if (result == null || result.ButtonType == ButtonType.Cancel)
            {
                result.Dispose();
                return;
            }

            result.Dispose();

            var vm = sender as ZipFileViewModel;

            Debug.Assert(vm != null);

            var option = win.RadioButtons[0].Checked ? 1 : win.RadioButtons[1].Checked ? 2 : 3;

            switch (option)
            {
            case 1:
                if (!DeleteZipFile(vm))
                {
                    MessageBox.Show($"Unable to delete {vm.Filename}.", "Exception");
                }
                break;

            case 2:
                DeleteRecord(vm);
                break;

            case 3:
                if (!DeleteZipFile(vm))
                {
                    var dr = MessageBox.Show($"Unable to delete {vm.Filename}. Do you want to delete the record anyway?", "Exception", MessageBoxButton.YesNo);
                    if (dr != MessageBoxResult.Yes)
                    {
                        return;
                    }
                }
                DeleteRecord(vm);
                break;

            default:
                throw new ArgumentException("Invalid radio button.");
            }
        }
コード例 #14
0
        /// <summary>
        /// The Vm_DeleteSelectedZipFilesRequested.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void Vm_DeleteSelectedZipFilesRequested(object sender, EventArgs e)
        {
            var vm    = DataContext as MainViewModel;
            var count = vm.SelectedZipFilesCollection.Count;

            var message = $"You have {count} zip file(s) selected and have initiated the delete function. What do you want to do?";
            var a       = Assembly.GetExecutingAssembly();
            var st      = a.GetManifestResourceStream("PluginManager.Wpf.Resources.qmark.ico");
            var qmark   = new Icon(st);

            var win = new TaskDialog()
            {
                WindowTitle    = "Delete Requested",
                MainIcon       = TaskDialogIcon.Custom,
                Content        = message,
                CustomMainIcon = qmark
            };

            var rb1 = new TaskDialogRadioButton()
            {
                Text = "Only delete zip files."
            };
            var rb2 = new TaskDialogRadioButton()
            {
                Text = "Only delete database records."
            };
            var rb3 = new TaskDialogRadioButton()
            {
                Text = "Delete both records and files.", Checked = true
            };
            var btn1 = new TaskDialogButton(ButtonType.Cancel);
            var btn2 = new TaskDialogButton(ButtonType.Ok);

            win.RadioButtons.Add(rb1);
            win.RadioButtons.Add(rb2);
            win.RadioButtons.Add(rb3);
            win.Buttons.Add(btn1);
            win.Buttons.Add(btn2);

            var result = win.ShowDialog();

            win.Dispose();
            qmark.Dispose();
            rb1.Dispose();
            rb2.Dispose();
            rb3.Dispose();
            btn1.Dispose();
            btn2.Dispose();
            st.Dispose();


            if (result == null || result.ButtonType == ButtonType.Cancel)
            {
                result.Dispose();
                return;
            }

            result.Dispose();

            // #Switch
            var option       = win.RadioButtons[0].Checked ? 1 : win.RadioButtons[1].Checked ? 2 : 3;
            var selectedZips = new List <ZipFileViewModel>(vm.SelectedZipFilesCollection);

            foreach (var item in selectedZips)
            {
                switch (option)
                {
                case 1:
                    if (!DeleteZipFile(item))
                    {
                        MessageBox.Show($"Unable to delete {item.Filename}.", "Exception");
                    }
                    break;

                case 2:
                    DeleteRecord(item);
                    break;

                case 3:
                    if (!DeleteZipFile(item))
                    {
                        var dr = MessageBox.Show($"Unable to delete {item.Filename}. Do you want to delete the record anyway?", "Exception", MessageBoxButton.YesNo);
                        if (dr != MessageBoxResult.Yes)
                        {
                            continue;
                        }
                    }
                    DeleteRecord(item);
                    break;

                default:
                    throw new ArgumentException("Invalid radio button.");
                }
            }
        }