Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Last active December 18, 2015 08:29
Show Gist options
  • Save pinzolo/5754639 to your computer and use it in GitHub Desktop.
Save pinzolo/5754639 to your computer and use it in GitHub Desktop.
[WPF]ウィンドウ表示時にデフォルトフォーカスを与える
<!-- Windowにて FocusManager.FocusedElement を設定する -->
<Window x:Class="MktSys.Gui.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Set default focus on Window shown" Height="525" Width="300"
FocusManager.FocusedElement="{Binding ElementName=TextBox}">
<Grid>
<TextBox Name="TextBox" HorizontalAlignment="Left" Height="25" Margin="0" TextWrapping="Wrap" VerticalAlignment="Top"/>
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment