Can't focus after closing a Confirm window

3 posts, 1 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 07 Mar 2014 Link to this post

                       When I close a cofirm radwindow  (showdialog()), it won't focus on a textbox.  If I change it to a regular wpf window and close it, everything is fine.
    When I debug it and step through it, it works so it could be some race condition.

    RadWindow.Confirm(new DialogParameters(){
     Owner = myMainpage,
                        DialogStartupLocation = WindowStartupLocation.CenterOwner,
                        Content =
                            message,
                        Closed = Cancel_Click
     ...
            private void Cancel_Click(object sender, Telerik.Windows.Controls.WindowClosedEventArgs e)
            {

                Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (System.Threading.ThreadStart)delegate()
                {

                    myTextBox.Focus();
                });
    //set the focus here
  2. Answer
    Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 12 Mar 2014 Link to this post

    Hello Dan,

    We were able to reproduce the described issue and I logged it in our Feedback portal. You can easily track its status on the following link:
    http://feedback.telerik.com/Project/143/Feedback/Details/122613-it-is-not-possible-to-focus-other-element-in-the-closed-event-handler-of-the-radw

    What I can suggest as a workaround would be to use a DispatcherTimer in order to focus the TextBox a little bit later. So if you are opening the Confirm dialog with a Button the code behind should looks as follows:

    private DispatcherTimer timer;
    public MainWindow()
    {
        InitializeComponent();
        timer = new DispatcherTimer();
        timer.Interval = new TimeSpan(0, 0, 0, 0, 600);
        timer.Tick += timer_Tick;
    }
     
    void timer_Tick(object sender, EventArgs e)
    {
        myTextBox.Focus();
        timer.Stop();
    }
     
    private void Cancel_Click(object sender, Telerik.Windows.Controls.WindowClosedEventArgs e)
    {
        timer.Start();
    }
     
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        RadWindow.Confirm(new DialogParameters()
        {
            Owner = Application.Current.MainWindow,
            DialogStartupLocation = WindowStartupLocation.CenterOwner,
            Content = "Test",
            Closed = Cancel_Click,
        });
    }

    Hope this will work for you. I have also updated your Telerik points for your involvement.

    Regards,
    Kalin
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 12 Mar 2014 in reply to Kalin Link to this post

    Thanks the workaround is great
Back to Top