4 Comments

If you want to set the focus on a textbox in Microsoft Silverlight, use the Loaded event and the System.Windows.Browser.HtmlPage.Plugin.Focus() prior to calling Control.Focus()

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Ada.Tts.Toggle.Silverlight
{
  public partial class MainPage : UserControl
  {
    /// <summary>
    /// Event fires on page load
    ///
    /// Set focus to search box
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
      System.Windows.Browser.HtmlPage.Plugin.Focus();
      this.searchTextBox.Focus();
    }
    /// <summary>
    /// Consturctor
    /// </summary>
    public MainPage()
    {
      InitializeComponent();
    }
  }
}

4 Replies to “Set focus to textbox in Microsoft Silverlight

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.