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

2 posts, 0 answers
  1. Michael
    Michael avatar
    2 posts
    Member since:
    Jul 2010

    Posted 09 May 2011 Link to this post

    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 .
  2. Pana
    Admin
    Pana avatar
    748 posts

    Posted 12 May 2011 Link to this post

    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
  3. DevCraft banner
Back to Top