
February 19, 2009 19:18 by
ColinW
In the Silverlight applications I’ve been working with recently, it seems that when you call focus on a control during startup, nothing appears to happen visually. I”m not sure if the root cause of the issue lies in the browser ( IE 7) or in Silverlight, as the work-around involves both.
In Silverlight, you’ll need to use the Dispatcher to execute your focus code:
Dispatcher.BeginInvoke(() => input3.Focus());
And in the actual page hosting the application, you’ll need to call .focus on the Silverlight control in Javascript:
setTimeout(function() { document.getElementById('Xaml1').focus(); }, 1);
What’s interesting is that both pieces of code delay the execution of the actual focus calls until after their current threads are running, and in the case of the javascript call, focusing does not work correctly if you use a timeout period of 0.
My guess is that a future version of Silverlight will remove the requirement of wrapping the focus call in a Dispatcher Invoke, but we’ll be stuck with IE not setting focus for a while.
- Colin
afc6bc92-73d0-4959-a9ba-1f5b0207182f|0|.0