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

Cannot focus any control under the BusyIndicator

1 Answer 128 Views
BusyIndicator
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 09 Dec 2011, 10:40 PM
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?

1 Answer, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 12 Dec 2011, 08:03 PM
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();
Tags
BusyIndicator
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Share this question
or