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

Is there a way to get a confirmation ask before close a RadWindow in Silverlight

1 Answer 63 Views
Window
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 09 May 2011, 04:09 PM
I used PreviewClose event, but it seemd not to reach my demand.I also tried RadWindow.Confirm() method in PreviewClose event,but the RadWindow was already be hidden before i clicked OK or Cancl button .

1 Answer, 1 is accepted

Sort by
0
Pana
Telerik team
answered on 12 May 2011, 08:07 AM
Hi Michael,

This can be a little tricky but actually the PreviewClose is the right event. You can set Cancel=false to prevent the window from closing if the close is not initiated by a Confirm reply. Refer to the following code:
And in XAML:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
  
namespace RadMenu_StretchItems
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
  
        private RadWindow w;
        private bool closeOnReply = false;
  
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (w == null)
            {
                w = new RadWindow();
                w.Show();
                w.PreviewClosed += new EventHandler<WindowPreviewClosedEventArgs>(w_PreviewClosed);
            }
        }
  
        void w_PreviewClosed(object sender, WindowPreviewClosedEventArgs e)
        {
            if (!closeOnReply)
            {
                e.Cancel = true;
                RadWindow.Confirm("Are you sure you want to close the window?", new EventHandler<WindowClosedEventArgs>(ConfirmClosed));
            }
        }
  
        void ConfirmClosed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                closeOnReply = true;
                w.Close();
                w = null;
                closeOnReply = false;
            }
        }
    }
}

And in XAML:

<UserControl x:Class="RadMenu_StretchItems.MainPage"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="800">
  
    <Grid x:Name="LayoutRoot" Background="White">
        <Button HorizontalAlignment="Center" VerticalAlignment="Center" Content="Open Window!" Click="Button_Click" />
    </Grid>
</UserControl>


Kind regards,
Pana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Window
Asked by
Michael
Top achievements
Rank 1
Answers by
Pana
Telerik team
Share this question
or