■ FocusManager 클래스의 FocusedElement 첨부 속성을 사용해 포커스를 설정하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="FocusManager 클래스 : FocusedElement 첨부 속성을 사용해 포커스 설정하기" FontFamily="나눔고딕코딩" FontSize="16" FocusManager.FocusedElement="{Binding ElementName=textBox2}"> <Grid HorizontalAlignment="Center" VerticalAlignment="Center"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Text="항목 1" /> <TextBox Name="textBox1" Grid.Row="0" Grid.Column="1" Margin="10 0 0 0" Width="200" Height="25" BorderThickness="1" BorderBrush="Black" VerticalContentAlignment="Center" /> <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="0 10 0 0" Text="항목 2" /> <TextBox Name="textBox2" Grid.Row="1" Grid.Column="1" Margin="10 10 0 0" Width="200" Height="25" BorderThickness="1" BorderBrush="Black" VerticalContentAlignment="Center" /> </Grid> </Window |