I have a TabControl that is bound to a view model
<TabControl
ItemsSource="{Binding Path=ViewModelCollection}" >
<TabControl.ItemContainerStyle>
<Style
TargetType="TabItem"
BasedOn="{StaticResource {x:Type TabItem}}">
<Setter
Property="Header"
Value="{Binding Title}" />
<Setter
Property="Content"
Value="{Binding}" />
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
Each Tab simply contains a View Model Item. I use a data template to display this.
<!-- View Model Template -->
<DataTemplate
DataType="{x:Type local:ViewModelItem}">
<DockPanel>
<TextBox Text="I want this to have the focus"/>
</DockPanel>
</DataTemplate>
When the current tab is changed i want the focus to be on the textbox (this is a simple example, in my production code i have a datagrid) in the data template. how do i accomplish this?