Cannot focus any control under the BusyIndicator

2 posts, 0 answers
  1. Paul
    Paul avatar
    102 posts
    Member since:
    Jun 2010

    Posted 09 Dec 2011 Link to this post

    Similar to:
    http://www.telerik.com/community/forums/wpf/busy-indicator/busyindicator-over-listbox-has-style-issue.aspx

    Steps:
    1. Set IsBusy to true.
    2. Set IsBusy to false.
    3. Set focus to something (anything!) under the BusyIndicator.
    Focus is never set.  I've tried the control.Focus() method as well as FocusManager options.

    Without setting IsBusy to true focus can be set as expected.

    Has anyone else seen this?
  2. Paul
    Paul avatar
    102 posts
    Member since:
    Jun 2010

    Posted 12 Dec 2011 Link to this post

    I solved it finally.  First I tried setting focus to the control I wanted which was a ListView.  Next, I tried setting focus to "this", followed by each parent container of the ListView in case the scope of the focus was wrong.  Next, I decided that setting IsBusy to false on the RadBusyIndicator must have something threaded and I'd have to call the focus at a separate time.

    At this point I created a Action and dispatched it with a priority of application idle.  This still did not solve it.

    Finally I put in a timer that I call ever 100ms but only for so many times.  This is terrible solution to me, but it does work as expected.

    DispatcherTimer t = new DispatcherTimer(DispatcherPriority.Normal);
    t.Tag = 0;
    t.Interval = TimeSpan.FromMilliseconds(100);
    t.Tick += (obj, e2) =>
    {            
       ((DispatcherTimer)t).Tag = ((int)((DispatcherTimer)t).Tag) + 1;

       lvSearch.Focus();
       if (lvSearch.Items.Count > 0)
       {
          ((ListViewItem)lvSearch.ItemContainerGenerator.ContainerFromIndex(0)).Focus();
       }

       if (((int)((DispatcherTimer)t).Tag > 5) || (FocusManager.GetFocusedElement(thisas ListViewItem != null))
       {
          ((DispatcherTimer)t).Stop();
       }
    };

    t.Start();
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top