recently in development Silverlight , there is a page that wants to set the focus on a TextBox allows the user to enter text directly.
Span style= "Font-family:verdana; Background-color:white ">silverlight To set the focus just set the" control " focus () method, but if you want to set the page one entry focus preset focus "
- Set First Plugin Focus, and then set the focus of the control item control
- Async at page initialization, placing the code of the preset focus in async
The code for the preset focus is as follows:
Using? System.Windows.Controls;
using? System.Windows.Browser;??? // Use HtmlPage to refer to this line first
namespace? SilverlightApplication1
{
???? public? partial? Class? MainPage?:? UserControl
???? {
???????? public? MainPage ()
???????? {
???????????? InitializeComponent ();
???????????? this. Loaded?+=? new? System.Windows.RoutedEventHandler (mainpage_loaded);
????????}
???????? void? Mainpage_loaded (objectsender,?) system.windows.routedeventargs?e)
???????? {
???????????? HtmlPage.Plugin.Focus ();? //to have this line in order to successfully set the control focus on one page
???????????? Textbox1.focus ();???????? // Then call to set the spotlight control Focus () method < Span style= "Font-family:courier New; Font-size:9pt ">
????????}
????}
}
Note: Use HtmlPage before you need to refer to System.Windows.Browser .
Silverlight Preset focus (default focus)