Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set autofocus only in xaml?

Is it possible, to set the autofocus to the textbox in my xaml file?

<Window x:Class="WpfApplication1.Views.Test1"             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             Height="100"             Width="210"             WindowStartupLocation="CenterOwner"             ShowInTaskbar="False"             Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"             ResizeMode="CanResizeWithGrip">     <TextBox HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap" AcceptsReturn="True" Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> </Window> 
like image 540
David Avatar asked Jun 28 '12 14:06

David


1 Answers

<TextBox FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}" /> 
like image 163
LPL Avatar answered Sep 19 '22 19:09

LPL