How to disable TextBox without focusing anything else

I believe that when my application starts, nothing focuses. At least it seems. I would like to add an event handler to the GotFocus event, so the control displays a popup and loses focus, so the popup can be displayed again without manually removing the focus and setting it back. In addition, it is not necessary that my text box in a focused visual state force its maintenance to be useless for the user (this can be changed by the template, but the answer to this question fixes both problems).

If I am mistaken with my initial observation, and something is always concentrated in silverlight, I would like to know what to focus on, so it seems that nothing focuses (for example, when the application starts). If there is a way to completely remove the visible focus, this approach would be better.

EDIT: Actually, in my case, it was a control that did not differ in visual differences when the focus was focused at the beginning of the application. I did not find anything smarter to do this in order to focus it on my Unfocus () related method. To go a little further, I can recommend pressing the [enter] key and see what happens, in my case it also changed the focused state of the control, it looked like it was not focused.

Note: in Silverlight there is no “nothing focused state”

+4
source share
1 answer

Focus in Silverlight is notoriously difficult to handle.

There are many controls that may have a focus that do not show visual difference when they have focus - very different from WinForms.

I found the following class useful in some of my Silverlight applications to try to figure out focus issues:

 public static class WatchWhatsGotFocus { private static DispatcherTimer t; public static void StartWatching() { t = new DispatcherTimer(); t.Interval = TimeSpan.FromMilliseconds(500); t.Tick += t_Tick; t.Start(); } public static void StopWatching() { if (t != null) { t.Stop(); t = null; } } static void t_Tick(object sender, EventArgs e) { var element = FocusManager.GetFocusedElement(); if (element != null) Debug.WriteLine("Focused element: {0}", element.ToString()); else { Debug.WriteLine("No focused element"); } } } 

So, somewhere in your application, just call WatchWhatsGotFocus.StartWatching () and you will see what happens.

+5
source

All Articles