FocusedElement is not being honoured
c#, focus, mvvm, prism, wpf
Solution
`FocusManager.FocusedElement="{Binding ElementName=Username}"` sets logical focus but not physical focus.
Physical focus is the normal focus, logical focus is kinda a second focus which is still a little bit buggy in wpf 4.0.
I would suggest you to use `Keyboard.Focus(this.Username)`.
Problem
I have created a basic application using Prism & MVVM. So far, it only consists of the Shell, and one View/ViewModel. During application load, I am loading the View into my main region and this displays on screen. This works, but I cannot get the textbox on the view to focus. It looks like the cursor is in the box (although it's not flashing), but it doesn't accept text input until I click on the textbox. I've recreated this in a new project, where all I've done is install prism/prism.unityextensions, set up the shell and the view, and loaded the view into the shell region. Neither xaml file has anything in the code behind. Shell ``` <Window x:Class="MVVMFocusTest.Shell" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:prism="http://www.codeplex.com/prism" Title="MainWindow" Height="350" Width="525"> <Grid> <DockPanel LastChildFill="True"> <ContentControl Name="MainRegion" DockPanel.Dock="Top" prism:RegionManager.RegionName="MainRegion" /> </DockPanel> </Grid> </Window> ``` View1 ``` <UserControl x:Class="MVVMFocusTest.View1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <StackPanel> <Grid FocusManager.FocusedElement="{Binding ElementName=Username}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="100" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Label Grid.Row="0" Grid.Column="0">Username</Label> <TextBox Name="Username" Grid.Row="0" Grid.Column="1" ToolTip="Enter Username" TabIndex="0" /> <Label Grid.Row="1" Grid.Column="0">Password</Label> <PasswordBox Grid.Row="1" Grid.Column="1" Name="LoginPassword" PasswordChar="*" ToolTip="Enter Password" TabIndex="1" /> </Grid> </StackPanel> </UserControl> ``` Can anyone point out what I'm doing wrong? As far as I'm aware, the `FocusManager.FocusedElement="{Binding ElementName=Username}"` should be sufficient to set the focus.