Note that there are some explanatory texts on larger screens.

plurals
  1. POWPFMVVM Set Control Focused
    primarykey
    data
    text
    <p>How in MVVM do you set a User Control Focus? Using Focusmanager.FocusElement={Binding ...} Has no affect.</p> <p>Here is my XAML:</p> <pre><code>&lt;DataTemplate DataType="{x:Type client:TelephoneNumberViewModel}"&gt; &lt;Grid FocusManager.FocusedElement="{Binding ElementName=TelephoneNumber}" Width="1024" Height="540"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="60" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="80" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="25" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;ColumnDefinition Width="*" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Margin="0 25 0 0" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="7" Name="textBlockQuestion" TextWrapping="Wrap" Style="{DynamicResource TitleTextBlock}"&gt;"What is your telephone number?"&lt;/TextBlock&gt; &lt;Grid Grid.Column="1" Grid.Row="1" Grid.RowSpan="7" Grid.ColumnSpan="7" Height="460"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="170" /&gt; &lt;ColumnDefinition /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="80" /&gt; &lt;RowDefinition Height="80" /&gt; &lt;RowDefinition Height="80" /&gt; &lt;RowDefinition Height="80" /&gt; &lt;RowDefinition Height="100" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel Grid.Row="0" Grid.RowSpan="5" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Top" HorizontalAlignment="Left"&gt; &lt;wpfclient:TelephoneBox Name="TelephoneNumber" TelephoneNumber="{Binding PhoneNumber, Mode=TwoWay}" /&gt; &lt;!--&lt;TextBox Width="500" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="40" TextAlignment="Center" Text="{Binding PhoneNumber}"&gt;&lt;/TextBox&gt;--&gt; &lt;StackPanel Orientation="Horizontal" Margin="0 40 0 0"&gt; &lt;StackPanel Orientation="Vertical" Margin="0 0 60 0" &gt; &lt;Button Margin="0 0 0 20" Style="{DynamicResource LargeGlossyButtonStyle}" Command="{Binding SurveyMobileCommand}"&gt;Mobile&lt;/Button&gt; &lt;Button Style="{DynamicResource LargeGlossyButtonStyle}" Command="{Binding SurveyHomeCommand}"&gt;Home&lt;/Button&gt; &lt;/StackPanel&gt; &lt;StackPanel Orientation="Vertical"&gt; &lt;Button Margin="0 0 0 20" Style="{DynamicResource LargeGlossyButtonStyle}" Command="{Binding SurveyWorkCommand}"&gt;Work&lt;/Button&gt; &lt;Button Style="{DynamicResource LargeGlossyButtonStyle}" Command="{Binding SurveyOtherCommand}"&gt;Other&lt;/Button&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; &lt;Grid Width="1024" Height="80" Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="8" VerticalAlignment="Bottom"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="*"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;ColumnDefinition Width="*"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Button Margin="60 0 0 20" Grid.Column="0" Grid.Row="0" Name="buttonContinue" Command="{Binding SurveySkipCommand}" Style="{DynamicResource LargeGlossyButtonStyle}" &gt;Skip&lt;/Button&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; </code></pre> <p>The user control does not get focus until I tab once still.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload