private void ExitResult(TaskDialogResult results)
 {
     if (results.Result == TaskDialogSimpleResult.Yes)
     {
         _parent.Close();
     }
 }
 private void ExitResults(TaskDialogResult obj)
 {
     if (obj.Result == TaskDialogSimpleResult.Yes)
     {
         _events.GetEvent<CloseGameEvent>().Publish(null);
     }
 }
Пример #3
0
        /// <summary>
        /// Shows a task dialog.
        /// </summary>
        /// <param name="sender">The owner of the dialog, or null.
        /// Should either be a window instance or the data context object of one.</param>
        /// <param name="options">A <see cref="T:TaskDialogOptions"/> config object.</param>
        /// <param name="callback">An optional callback method.</param>
        public void ShowTaskDialog(object sender, TaskDialogOptions options, Action<TaskDialogResult> callback)
        {
            MessageBoxButton buttons = MessageBoxButton.OK;

            if (options.AllowDialogCancellation
                || (options.CommonButtons == TaskDialogCommonButtons.OKCancel
                    || options.CommonButtons == TaskDialogCommonButtons.RetryCancel
                    || options.CommonButtons == TaskDialogCommonButtons.YesNo
                    || options.CommonButtons == TaskDialogCommonButtons.YesNoCancel))
                buttons = MessageBoxButton.OKCancel;

            MessageBoxResult mbResult =
                MessageBox.Show(
                    String.IsNullOrEmpty(options.MainInstruction) ? options.Content : options.MainInstruction,
                    options.Title,
                    buttons);

            TaskDialogResult tdResult = new TaskDialogResult((TaskDialogSimpleResult)mbResult);
        }
Пример #4
0
 /// <summary>
 /// Utility method, checks if the <see cref="Callback" /> property is
 /// null, and if it is not null, executes it.
 /// </summary>
 /// <param name="result">The result that must be passed
 /// to the task dialog message caller.</param>
 public void ProcessCallback(TaskDialogResult result)
 {
     if (Callback != null)
         Callback(result);
 }
Пример #5
0
        private static TaskDialogResult ShowTaskDialog(TaskDialogOptions options)
        {
            VistaTaskDialog vtd = new VistaTaskDialog();

            vtd.WindowTitle = options.Title;
            vtd.MainInstruction = options.MainInstruction;
            vtd.Content = options.Content;
            vtd.ExpandedInformation = options.ExpandedInfo;
            vtd.Footer = options.FooterText;

            if (options.CommandButtons != null && options.CommandButtons.Length > 0)
            {
                List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>();
                for (int i = 0; i < options.CommandButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId = GetButtonIdForCommandButton(i);
                        button.ButtonText = options.CommandButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue
                    && options.DefaultButtonIndex >= 0
                    && options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
            }
            else if (options.RadioButtons != null && options.RadioButtons.Length > 0)
            {
                List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>();
                for (int i = 0; i < options.RadioButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId = GetButtonIdForRadioButton(i);
                        button.ButtonText = options.RadioButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.RadioButtons = lst.ToArray();
                vtd.NoDefaultRadioButton = (!options.DefaultButtonIndex.HasValue || options.DefaultButtonIndex.Value == -1);
                if (options.DefaultButtonIndex.HasValue
                    && options.DefaultButtonIndex >= 0
                    && options.DefaultButtonIndex.Value < vtd.RadioButtons.Length)
                    vtd.DefaultButton = vtd.RadioButtons[options.DefaultButtonIndex.Value].ButtonId;
            }

            bool hasCustomCancel = false;

            if (options.CustomButtons != null && options.CustomButtons.Length > 0)
            {
                List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>();
                for (int i = 0; i < options.CustomButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId = GetButtonIdForCustomButton(i);
                        button.ButtonText = options.CustomButtons[i];

                        if (!hasCustomCancel)
                        {
                            hasCustomCancel =
                                (button.ButtonText == "Close"
                                || button.ButtonText == "Cancel");
                        }

                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }

                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue
                    && options.DefaultButtonIndex.Value >= 0
                    && options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                vtd.CommonButtons = VistaTaskDialogCommonButtons.None;
            }
            else
            {
                vtd.CommonButtons = ConvertCommonButtons(options.CommonButtons);

                if (options.DefaultButtonIndex.HasValue
                    && options.DefaultButtonIndex >= 0)
                    vtd.DefaultButton = GetButtonIdForCommonButton(options.CommonButtons, options.DefaultButtonIndex.Value);
            }

            vtd.MainIcon = options.MainIcon;
            vtd.CustomMainIcon = options.CustomMainIcon;
            vtd.FooterIcon = options.FooterIcon;
            vtd.CustomFooterIcon = options.CustomFooterIcon;
            vtd.EnableHyperlinks = DetectHyperlinks(options.Content, options.ExpandedInfo, options.FooterText);
            vtd.AllowDialogCancellation =
                (options.AllowDialogCancellation
                || hasCustomCancel
                || options.CommonButtons == TaskDialogCommonButtons.Close
                || options.CommonButtons == TaskDialogCommonButtons.OKCancel
                || options.CommonButtons == TaskDialogCommonButtons.YesNoCancel);
            vtd.CallbackTimer = options.EnableCallbackTimer;
            vtd.ExpandedByDefault = options.ExpandedByDefault;
            vtd.ExpandFooterArea = options.ExpandToFooter;
            vtd.PositionRelativeToWindow = true;
            vtd.RightToLeftLayout = false;
            vtd.NoDefaultRadioButton = false;
            vtd.CanBeMinimized = false;
            vtd.ShowProgressBar = options.ShowProgressBar;
            vtd.ShowMarqueeProgressBar = options.ShowMarqueeProgressBar;
            vtd.UseCommandLinks = (options.CommandButtons != null && options.CommandButtons.Length > 0);
            vtd.UseCommandLinksNoIcon = false;
            vtd.VerificationText = options.VerificationText;
            vtd.VerificationFlagChecked = options.VerificationByDefault;
            vtd.ExpandedControlText = "Hide details";
            vtd.CollapsedControlText = "Show details";
            vtd.Callback = options.Callback;
            vtd.CallbackData = options.CallbackData;
            vtd.Config = options;

            TaskDialogResult result = null;
            int diagResult = 0;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked = false;
            int radioButtonResult = -1;
            int? commandButtonResult = null;
            int? customButtonResult = null;

            diagResult = vtd.Show((vtd.CanBeMinimized ? null : options.Owner), out verificationChecked, out radioButtonResult);

            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            else if (radioButtonResult >= RadioButtonIDOffset)
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
                radioButtonResult -= RadioButtonIDOffset;
            }
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandButtons == null || options.CommandButtons.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return result;
        }
Пример #6
0
        private static TaskDialogResult ShowEmulatedTaskDialog(TaskDialogOptions options)
        {
            TaskDialog td = new TaskDialog();
            TaskDialogViewModel tdvm = new TaskDialogViewModel(options);

            td.DataContext = tdvm;

            if (options.Owner != null)
            {
                td.Owner = options.Owner;
            }

            td.ShowDialog();

            TaskDialogResult result = null;
            int diagResult = -1;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked = false;
            int radioButtonResult = -1;
            int? commandButtonResult = null;
            int? customButtonResult = null;

            diagResult = tdvm.DialogResult;
            radioButtonResult = tdvm.RadioResult - RadioButtonIDOffset;
            verificationChecked = tdvm.VerificationChecked;

            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            //else if (diagResult >= RadioButtonIDOffset)
            //{
            //    simpResult = (TaskDialogSimpleResult)diagResult;
            //    radioButtonResult = diagResult - RadioButtonIDOffset;
            //}
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            // This occurs usually when the red X button is clicked
            else if (diagResult == -1)
            {
                simpResult = TaskDialogSimpleResult.Cancel;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandButtons == null || options.CommandButtons.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return result;
        }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskDialogClosedEventArgs"/> class.
 /// </summary>
 /// <param name="result">The result of the TaskDialog.</param>
 internal TaskDialogClosedEventArgs(TaskDialogResult result)
 {
     Result = result;
 }
Пример #8
0
        private static TaskDialogResult ShowTaskDialog(TaskDialogOptions options)
        {
            VistaTaskDialog vtd = new VistaTaskDialog();

            vtd.WindowTitle         = options.Title;
            vtd.MainInstruction     = options.MainInstruction;
            vtd.Content             = options.Content;
            vtd.ExpandedInformation = options.ExpandedInfo;
            vtd.Footer = options.FooterText;

            if (options.CommandButtons != null && options.CommandButtons.Length > 0)
            {
                List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                for (int i = 0; i < options.CommandButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId   = GetButtonIdForCommandButton(i);
                        button.ButtonText = options.CommandButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                {
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }
            else if (options.RadioButtons != null && options.RadioButtons.Length > 0)
            {
                List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                for (int i = 0; i < options.RadioButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId   = GetButtonIdForRadioButton(i);
                        button.ButtonText = options.RadioButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.RadioButtons         = lst.ToArray();
                vtd.NoDefaultRadioButton = (!options.DefaultButtonIndex.HasValue || options.DefaultButtonIndex.Value == -1);
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < vtd.RadioButtons.Length)
                {
                    vtd.DefaultButton = vtd.RadioButtons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }

            bool hasCustomCancel = false;

            if (options.CustomButtons != null && options.CustomButtons.Length > 0)
            {
                List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                for (int i = 0; i < options.CustomButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId   = GetButtonIdForCustomButton(i);
                        button.ButtonText = options.CustomButtons[i];

                        if (!hasCustomCancel)
                        {
                            hasCustomCancel =
                                (button.ButtonText == "Close" ||
                                 button.ButtonText == "Cancel");
                        }

                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }

                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex.Value >= 0 &&
                    options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                {
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
                vtd.CommonButtons = VistaTaskDialogCommonButtons.None;
            }
            else
            {
                vtd.CommonButtons = ConvertCommonButtons(options.CommonButtons);

                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0)
                {
                    vtd.DefaultButton = GetButtonIdForCommonButton(options.CommonButtons, options.DefaultButtonIndex.Value);
                }
            }

            vtd.MainIcon                = options.MainIcon;
            vtd.CustomMainIcon          = options.CustomMainIcon;
            vtd.FooterIcon              = options.FooterIcon;
            vtd.CustomFooterIcon        = options.CustomFooterIcon;
            vtd.EnableHyperlinks        = DetectHyperlinks(options.Content, options.ExpandedInfo, options.FooterText);
            vtd.AllowDialogCancellation =
                (options.AllowDialogCancellation ||
                 hasCustomCancel ||
                 options.CommonButtons == TaskDialogCommonButtons.Close ||
                 options.CommonButtons == TaskDialogCommonButtons.OKCancel ||
                 options.CommonButtons == TaskDialogCommonButtons.YesNoCancel);
            vtd.CallbackTimer            = options.EnableCallbackTimer;
            vtd.ExpandedByDefault        = options.ExpandedByDefault;
            vtd.ExpandFooterArea         = options.ExpandToFooter;
            vtd.PositionRelativeToWindow = true;
            vtd.RightToLeftLayout        = false;
            vtd.NoDefaultRadioButton     = false;
            vtd.CanBeMinimized           = false;
            vtd.ShowProgressBar          = options.ShowProgressBar;
            vtd.ShowMarqueeProgressBar   = options.ShowMarqueeProgressBar;
            vtd.UseCommandLinks          = (options.CommandButtons != null && options.CommandButtons.Length > 0);
            vtd.UseCommandLinksNoIcon    = false;
            vtd.VerificationText         = options.VerificationText;
            vtd.VerificationFlagChecked  = options.VerificationByDefault;
            vtd.ExpandedControlText      = "Hide details";
            vtd.CollapsedControlText     = "Show details";
            vtd.Callback     = options.Callback;
            vtd.CallbackData = options.CallbackData;
            vtd.Config       = options;

            TaskDialogResult result           = null;
            int diagResult                    = 0;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked          = false;
            int  radioButtonResult            = -1;
            int? commandButtonResult          = null;
            int? customButtonResult           = null;

            //diagResult = vtd.Show((vtd.CanBeMinimized ? null : options.Owner), out verificationChecked, out radioButtonResult);

            IntPtr ownerHandle = options.OwnerHandle;

            if (options.Owner != null)
            {
                WindowInteropHelper helper = new WindowInteropHelper(options.Owner);
                ownerHandle = helper.Owner;
            }
            diagResult = vtd.Show((vtd.CanBeMinimized ? IntPtr.Zero : ownerHandle), out verificationChecked, out radioButtonResult);


            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult          = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            else if (radioButtonResult >= RadioButtonIDOffset)
            {
                simpResult         = (TaskDialogSimpleResult)diagResult;
                radioButtonResult -= RadioButtonIDOffset;
            }
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult         = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandButtons == null || options.CommandButtons.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return(result);
        }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskDialogClosedEventArgs"/> class.
 /// </summary>
 /// <param name="result">The result of the TaskDialog.</param>
 internal TaskDialogClosedEventArgs(TaskDialogResult result)
 {
     Result = result;
 }
Пример #10
0
        private void UpdateResult(TaskDialogResult res)
        {
            if (res == null)
            {
                lbResult.Text = "Task Dialog Result";
                return;
            }

            StringBuilder strBldr = new StringBuilder();

            strBldr.AppendLine("Task Dialog Result");
            strBldr.AppendLine("Simple Result: " + res.Result.ToString());

            if (res.RadioButtonResult.HasValue)
            {
                strBldr.AppendLine("RadioButtonResult: " + res.RadioButtonResult.ToString());
            }
            else
            {
                strBldr.AppendLine("RadioButtonResult: <null>");
            }

            if (res.CommandButtonResult.HasValue)
            {
                strBldr.AppendLine("CommandButtonResult: " + res.CommandButtonResult.ToString());
            }
            else
            {
                strBldr.AppendLine("CommandButtonResult: <null>");
            }

            if (res.CustomButtonResult.HasValue)
            {
                strBldr.AppendLine("CustomButtonResult: " + res.CustomButtonResult.ToString());
            }
            else
            {
                strBldr.AppendLine("CustomButtonResult: <null>");
            }

            if (res.VerificationChecked.HasValue)
            {
                strBldr.Append("VerificationChecked: " + res.VerificationChecked.ToString());
            }
            else
            {
                strBldr.Append("VerificationChecked: <null>");
            }

            lbResult.Text = strBldr.ToString();
        }