How can I mark textBox as a default focus ?
When the windows is start , when the user press something it will be write on this textbox
Thanks
How can I mark textBox as a default focus ?
When the windows is start , when the user press something it will be write on this textbox
Thanks
Bind the FocusManager.FocusedElement
attached property of the root panel to the TextBox
:
<StackPanel FocusManager.FocusedElement="{Binding ElementName=tb}">
<TextBox x:Name="tb" Background="Beige" Text="..."/>
</StackPanel>
This will will work if you have a single focus scope, or if the focus scope to which the TextBox
belongs currently has keyboard focus.
You could also use the Keyboard.Focus
method to set the keyboard focus:
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
InitializeComponent();
Loaded += (s, e) => Keyboard.Focus(tb);
}
}
There can be only one element on the whole desktop that has keyboard focus. Please refer to MSDN for more information.
Focus Overview: https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/focus-overview