0

I'm using radwindow for my custom confirmbox in my WPF application. Now i need to get the result which the user clicked without firing an event.

//Code:

    DialogParameters param = new DialogParameters();
    param.Theme = new Windows8Theme();
    param.OkButtonContent = "Save";
    param.CancelButtonContent = "Discard";
    param.Content = "Do you want to save your unsaved changes?";
    param.Header = "";

    RadWindow.Confirm(param);

Somehting like,

DialogResult result = MessageBox.Show("Do you want to save changes?", "Confirmation", messageBoxButtons.YesNoCancel);
if(result == DialogResult.Yes)
    //...
else if (result == DialogResult.No)
    //...
else
    //...

How to achieve this?

rdmptn
  • 5,413
  • 1
  • 16
  • 29
A Coder
  • 3,039
  • 7
  • 58
  • 129

2 Answers2

1

See if this works for you. I subclassed the RadWindow object.

public class MyWindow : RadWindow
{
    #region Public Methods

    /// <summary>
    /// Alerts the specified message.
    /// </summary>
    /// <param name="message">The message.</param>
    /// <param name="width">The width.</param>
    public static void Alert(string message, int width = 400 )
    {
        var dialogParams = new DialogParameters
        {
            Content = new TextBlock()
            {
                Text = message,
                Width = width,
                TextWrapping = TextWrapping.Wrap
            },            
            Owner = Application.Current.MainWindow
        };

        RadWindow.Alert(dialogParams);
    }

    /// <summary>
    /// Confirms the specified content.
    /// </summary>
    /// <param name="message">The content.</param>
    /// <param name="closed">The closed.</param>
    /// <param name="width">The width.</param>
    public static void Confirm(string message, EventHandler<WindowClosedEventArgs> closed, int width = 400)
    {
        RadWindow.Confirm(new DialogParameters
        {
            Content = new TextBlock()
            {                   
                Text = message,
                Width = width,                   
                TextWrapping = TextWrapping.Wrap
            },
            Closed = closed,                  
            Owner = Application.Current.MainWindow
        });
    }

    #endregion Public Methods
}

Then make a call like this...

                MyWindow.Confirm(message,
                    delegate(object windowSender, WindowClosedEventArgs args)
                    {
                        if (args.DialogResult == true)
                        {
                            this.securityViewModel.UndeleteUser(fex.Detail.ExistingDeletedUserId.Value);
                        }
                    });
LawMan
  • 3,469
  • 1
  • 29
  • 32
0

RadWindow.Confirm also takes another argument, it's a handler to execute in OnClose

I solved this way:

bool DialogResult = false;
public void ShowConfirmation(string Message){
    DialogParameters param = new DialogParameters();
    param.Content = message;
    param.Owner = App.Current.MainWindow;
    param.Closed += (object sender, WindowClosedEventArgs e) => {
                DialogResult = e.DialogResult == true ? true : false;
            }; 

    RadWindow.Confirm(param);
    return DialogResult
}

e.DialogResult it's a nullable bool and I save it in a variable defined elsewhere in the code( In my case DialogResult, it's defined outside the method that calls the Dialog so I can use it in the method, and the lambda handler function).