private void OpenRecentFileCommand_Executed(object sender, ExecutedRoutedEventArgs e) { var entry = (MRULib.MRU.Interfaces.IMRUEntryViewModel)e.Parameter; var model = (AppModel)DataContext; try { model.MsiPath = entry.PathFileName; } catch (WixToolset.Dtf.WindowsInstaller.InstallerException) { TaskDialogPage page = new TaskDialogPage { AllowCancel = true, Title = "MSI Viewer", Instruction = $"The file {entry.File.Name} does not exist. Would you like to remove it from the Recent Files list?", Icon = TaskDialogIcon.Get(TaskDialogStandardIcon.Warning), }; TaskDialogCustomButton removeButton = new TaskDialogCustomButton("Remove"); removeButton.DefaultButton = true; page.CustomButtons.Add(removeButton); page.StandardButtons.Add(TaskDialogResult.Cancel); TaskDialog dialog = new TaskDialog(page); if (dialog.Show(this).Equals(removeButton)) { model.RemoveMRUItem(entry); } } }
private static void ShowTaskDialog() { TaskDialogPage taskDialogPage = new TaskDialogPage { Title = "USB Function Mode Switcher", Instruction = "Select a USB function mode to switch to", Text = "Below are the available modes your phone supports switching to.", Footer = { Text = "Switching modes will require a reboot of the device.", Icon = TaskDialogStandardIcon.Warning }, CustomButtonStyle = TaskDialogCustomButtonStyle.CommandLinks, AllowCancel = true, SizeToContent = true }; TaskDialog dialog = new TaskDialog(taskDialogPage); ModeHandler handler = new ModeHandler(); if (ModeHandler.IsUSBC()) { TaskDialogCustomButton taskDialogCustomButton = taskDialogPage.CustomButtons.Add("Host mode (Power output disabled)", "Default mode of the device. Enables connecting USB devices to the phone using the Continuum dock or any powered USB docking station or hub."); TaskDialogCustomButton taskDialogCustomButton2 = taskDialogPage.CustomButtons.Add("Host mode (Power output enabled) (Unsafe, read before enabling)", "Enables connecting USB devices to the phone using a standard USB cable, non powered USB docking station, or any non powered hub.\n\nImportant: Do not plug a cable transmiting power into the device when running in this mode. This includes a charging cable, PC USB port, wall charger or Continuum dock. Doing so will harm your device!"); switch (handler.CheckCurrentMode()) { case ModeHandler.USBModes.HostNonPowered: taskDialogCustomButton.Enabled = false; break; case ModeHandler.USBModes.HostPowered: taskDialogCustomButton2.Enabled = false; break; } taskDialogCustomButton.Click += delegate { handler.SetCurrentMode(ModeHandler.USBModes.HostNonPowered); Process.Start("shutdown", "/s /t 10 /f"); }; taskDialogCustomButton2.Click += delegate(object sender, TaskDialogButtonClickedEventArgs args) { args.CancelClose = true; TaskDialogPage taskDialogPage2 = new TaskDialogPage(); taskDialogPage2.Title = "USB Function Mode Switcher"; taskDialogPage2.Text = "Switching to this mode will enable power output from the USB Type C port. This may harm your device if you plug in a charging cable or a continuum dock. In this mode NEVER plug in any charging cable, wall charger, PC USB Cable (connected to a PC) or any externally powered USB hub! We cannot be taken responsible for any damage caused by this, you have been warned!"; taskDialogPage2.Instruction = "Do you really want to do this?"; taskDialogPage2.Icon = TaskDialogStandardIcon.Warning; taskDialogPage2.CustomButtonStyle = TaskDialogCustomButtonStyle.CommandLinks; taskDialogPage2.AllowCancel = true; taskDialogPage2.SizeToContent = true; taskDialogPage2.CustomButtons.Add("No"); taskDialogPage2.CustomButtons.Add("Yes I understand all the risks").Click += delegate { handler.SetCurrentMode(ModeHandler.USBModes.HostPowered); Process.Start("shutdown", "/s /t 10 /f"); dialog.Close(); }; new TaskDialog(taskDialogPage2).Show(); }; } TaskDialogCustomButton taskDialogCustomButton3 = taskDialogPage.CustomButtons.Add("Function mode (Retail)", "Enables MTP, NCSd, IPOverUSB and VidStream connections from another computer. Windows Phone Normal USB Mode."); TaskDialogCustomButton taskDialogCustomButton4 = taskDialogPage.CustomButtons.Add("Function mode (Serial)", "Enables DIAG, MODEM, NMEA and TRACE connections from another computer. Qualcomm Serial Diagnostics Mode."); TaskDialogCustomButton taskDialogCustomButton5 = taskDialogPage.CustomButtons.Add("Function mode (RmNet)", "Enables DIAG, NMEA, MODEM and RMNET connections from another computer. Qualcomm Wireless Diagnostics Mode."); TaskDialogCustomButton taskDialogCustomButton6 = taskDialogPage.CustomButtons.Add("Function mode (DPL)", "Enables DIAG, MODEM, RMNET and DPL connections from another computer. Qualcomm Data Protocol Logging Mode."); switch (handler.CheckCurrentMode()) { case ModeHandler.USBModes.FunctionDPL: taskDialogCustomButton6.Enabled = false; break; case ModeHandler.USBModes.FunctionRetail: taskDialogCustomButton3.Enabled = false; break; case ModeHandler.USBModes.FunctionRmNet: taskDialogCustomButton5.Enabled = false; break; case ModeHandler.USBModes.FunctionSerial: taskDialogCustomButton4.Enabled = false; break; } taskDialogCustomButton6.Click += delegate { handler.SetCurrentMode(ModeHandler.USBModes.FunctionDPL); Process.Start("shutdown", "/s /t 10 /f"); }; taskDialogCustomButton3.Click += delegate { handler.SetCurrentMode(ModeHandler.USBModes.FunctionRetail); Process.Start("shutdown", "/s /t 10 /f"); }; taskDialogCustomButton5.Click += delegate { handler.SetCurrentMode(ModeHandler.USBModes.FunctionRmNet); Process.Start("shutdown", "/s /t 10 /f"); }; taskDialogCustomButton4.Click += delegate { handler.SetCurrentMode(ModeHandler.USBModes.FunctionSerial); Process.Start("shutdown", "/s /t 10 /f"); }; dialog.Show(); }
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); }