Tuesday, July 28, 2009

Focus a Silverlight control on startup

I found two solutions to this problem on the web and neither of them worked for me. I finally combined both of them to make it work:

In the aspx page, include

<script type="text/javascript">
window.onload = function()
{
setTimeout(function() { document.getElementById('Xaml1').focus(); }, 1);
}
</script>

And then in Page.cs class as a response to Loaded event:

Dispatcher.BeginInvoke(delegate{myControl.Focus();});

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home