This is a migrated thread and some comments may be shown as answers.

RadWindow notify user before closing with 'X' button

2 Answers 138 Views
Window
This is a migrated thread and some comments may be shown as answers.
Prashant
Top achievements
Rank 1
Prashant asked on 08 Nov 2019, 12:16 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 08 Nov 2019, 10:08 AM

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.
0
Prashant
Top achievements
Rank 1
answered on 10 Nov 2019, 11:12 PM

Really appreciate your help Dinko, working as expected.

Regards,

Prashant

 

 

Tags
Window
Asked by
Prashant
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Prashant
Top achievements
Rank 1
Share this question
or