Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I whipped up a quick SL3 app and it <em>is</em> difficult to have the initial focus go to the UserControl let alone to a control within the Silverlight control.</p> <p>However, see if <a href="http://silverlight.net/forums/t/12865.aspx" rel="noreferrer">this solution</a> solves this issue for you. You'll have to use a little JavaScript.</p> <p>Here's the code for reference:</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" %&gt; &lt;%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" style="height:100%;"&gt; &lt;head runat="server"&gt; &lt;title&gt;Test Page For TextFocusTest&lt;/title&gt; &lt;script type="text/javascript"&gt; window.onload = function() { document.getElementById('Xaml1').focus(); } &lt;/script&gt; &lt;/head&gt; &lt;body style="height:100%;margin:0;"&gt; &lt;form id="form1" runat="server" style="height:100%;"&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;&lt;/asp:ScriptManager&gt; &lt;div style="height:100%;"&gt; &lt;asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/TextFocusTest.xap" Version="2.0" Width="100%" Height="100%" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Once your SL control has focus, you can further set the focus to a specific control using something like:</p> <pre><code>namespace SilverlightApplication2 { public partial class MainPage : UserControl { public MainPage () { InitializeComponent (); this.GotFocus += new RoutedEventHandler (MainPage_GotFocus); } void MainPage_GotFocus (object sender, RoutedEventArgs e) { uxLogin.Focus (); } } } </code></pre> <p>where uxLogin is defined in XAML as:</p> <pre><code>&lt;TextBox x:Name="uxLogin" Height="25" Width="100" /&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload