Is it possible, to set the autofocus to the textbox in my xaml file?
I usually resolve this with C#
textBox1.Focus();
I think it is the best way how to do this.
I think binding is an overkill, Reference is more lightweight:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FocusManager.FocusedElement="{x:Reference textBox1}">
<StackPanel>
<TextBox x:Name="textBox1" />
</StackPanel>
</Window>
<TextBox FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" />
try somethind like this
<Window x:Class="WpfApplication18.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="500" Width="525" FocusManager.FocusedElement="textcontrol">
<Grid>
<TextBox Name="textcontrol" />
</Grid>
</Window>
yes you can use FocusManager.FocusedElement attached property.
FocusManager.FocusedElement="{Binding ElementName=textBox1}"