Adjust focus to new controls

I have a ListBox that receives new items added to it via the Databinding (i.e., something is added to the list and the window is updated to include the new item).

The elements in the list are editable data templates, so the question arises: how to adjust focus on the first field in the template when adding a new element?

I reviewed this question and I will see if it will deliver me anywhere, but this is not really a direct answer to my question.

+5
source share
1 answer

, , . ObservableCollection , :

<ListBox IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding MyCollection}" ItemTemplate="{StaticResource MyTemplate}/>

, , ( ) TextBox. MSDN , :

<DataTemplate x:Key="MyTemplate" DataType="{x:Type Classes:MyClass}">    
  <StackPanel FocusManager.FocusedElement="{Binding ElementName=firstButton}">
    <Button Name="firstButton" />
  </StackPanel>
</DataTemplate>
+7

All Articles