RadWindow notify user before closing with 'X' button

3 posts, 1 answers
  1. Prashant
    Prashant avatar
    12 posts
    Member since:
    Jun 2017

    Posted 07 Nov Link to this post

    Hi All,

    I am opening RadWindow with ShowDialog() from viewmodel. I am not able to detect close 'X' button event. I want to prompt user before closing. 

    My code looks like:

    AssetViewModel.cs

    var AssetWindow = new RadWindow
                {
                    Header = "Asset Information",
                    Owner = Application.Current.MainWindow,                
                    WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner,
                    Content = new UserControl()
                };          
    AssetWindow.ShowDialog();

    What is the best approach to detect close event, prompt user and proceed with user selected option i.e Yes/No

     Any help would be appreciated,

    Regards,

    Prashant Kirpan

     

     

     

  2. Answer
    Dinko
    Admin
    Dinko avatar
    952 posts

    Posted 08 Nov Link to this post

    Hello Prashant,

    Thank you for the provided code snippet.

    You can subscribe to the PreviewClosed event of the RadWindow and show a confirm dialog, for example, and if the user doesn't want to close, you can set the Cancel property to true.

    var AssetWindow = new RadWindow
    {
        Header = "Asset Information",
        Owner = Application.Current.MainWindow,
        WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner,
        Content = new UserControl()
    };
    AssetWindow.PreviewClosed += AssetWindow_PreviewClosed;
    AssetWindow.ShowDialog();

    private void AssetWindow_PreviewClosed(object sender, WindowPreviewClosedEventArgs e)
    {
        e.Cancel = true;
    }

    Regards,
    Dinko
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Prashant
    Prashant avatar
    12 posts
    Member since:
    Jun 2017

    Posted 10 Nov in reply to Dinko Link to this post

    Really appreciate your help Dinko, working as expected.

    Regards,

    Prashant

     

     

Back to Top