Blog

How To Make Sure the Silverlight App Gets Keyboard focus

Posted by Mike Gold Blogs | XAML Sep 02, 2008
After playing with silverlight for a while, I found that the Focus method did not work very well to give the silverlight app focus for keyboard input. You can use a trick in javascript to make sure that the silverlight control has focus to begin with. Then later use the Focus method inside your XAML code behind.

The following sample shows you how to force focus to the silverlight control when your aspx page comes up.  In the body tag add the following javascript (where XAML1 is the ID of your Silverlight control

<body onload="document.getElementById('XAML1').focus()" style="height:100%;margin:0;">

Your Silverlight control tag should already look something like this.

<asp:Silverlight ID="XAML1" runat="server" Source="~/ClientBin/MySilverlightApp.xap" MinimumVersion="2.0.30523" Width="100%" Height="100%" />

post comment
     

I have a very strange issue in my application when its get deployed in HTTPS environment.I have two text boxes which is a silveright user control.I just used this control in an aspx page which has two buttons save and cancel buttons.When i click the save button using mouse after entering the values in the text boxes, the value is not captured.if i simply click the user control before click the save button, the value is captured.if i use the keyboard to press the save button (using tab and press the space bar or enter button), the value is captured.Does the issue related to focus problem in silverlight control ?Can you provide me a solution for this ?

Posted by Manikavelu Velayutham Aug 18, 2011
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter