wpf

[WPF] FocusManager

This is to set focus when a wpf program is initialed.

Example:

<StackPanel Orientation="Horizontal"
                    FocusManager.FocusedElement="{Binding ElementName=TxtKeyword}">
            <Label Content="Enter your city name/zipcode: "/>
            <TextBox Text="{Binding Keyword}"
                     Name="TxtKeyword"
                     Margin="5"
                     Width="100"
                     Height="20"></TextBox>
            <Button Command="{Binding SearchCommand}" 
                    Content="Search" 
                    Margin="5" 
                    Width="50"
                    Height="20"
                    FontSize="10"></Button>
            <Button Command="{Binding ClearCommand}" 
                    Content="Clear" 
                    Margin="5" 
                    Width="50"
                    Height="20"
                    FontSize="10">
                <i:Interaction.Behaviors>
                    <behaviors:GetFocusBehavior FocusElement="{Binding ElementName=TxtKeyword, Mode=OneWay}"/>
                </i:Interaction.Behaviors>
            </Button>
        </StackPanel>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s