Search This Blog

Thursday, March 2, 2017

FrameworkElementFactory focus on load element

WPF > FrameworkElementFactory > AddHandler


FrameworkElementFactory textBox = new FrameworkElementFactory(typeof(TextBox));
textBox.AddHandler(TextBox.LoadedEvent, new RoutedEventHandler(OnTextBoxLoaded));

private void OnTextBoxLoaded(object sender, RoutedEventArgs e)
{
       TextBox textBox = sender as TextBox;
       if (textBox != null)
       {
              textBox.Focus();
       }
}