Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

navigating through wpf TabItem and set focus on control

$
0
0

Hi, I  make a next button on a tabitem, so when user click it, it set focus to the next tabItem and focus on a particular TextBox but the focus setting on the TextBox, doesn't work

here is the code's sample

XAML

<TabControl><TabItem x:Name="Item1" Header="tabItem1"><TextBox x:Name="txtName" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,50,0,0" width="100" height="25" /><Button x:Name="btnNext" Content=" Next " VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,75,0,0" Height="35" Click="bntNext_Click"/></TabItem>

<TabItem x:Name="Item2" Header="tabItem2"><TextBox x:Name="txtProfession" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,50,0,0" width="100" height="25" /><TextBox x:Name="txtCompany" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,75,0,0" width="100" height="25" /></TabItem>

<TabItem x:Name="Item3" Header="tabItem3"><TextBox x:Name="txtEmail" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,50,0,0" width="100" height="25" /></TabItem></TabControl>

VB.NET

Private Sub btnNext_Click(sender As Object, e As RoutedEventArgs)
  Item2.IsSelected = True
  'I also try
  'Item2.focus()
  If Not txtCompany.IsFocused Then
    'here I want to set Focus on txtCompany
    txtCompany.Focus()

    'I also Try
    'Keyboard.Focus(txtCompany)
    'Dispatcher.BeginInvoke(DirectCast(Sub() txtCompany.Focus(), System.Threading.ThreadStart))
  End If
End Sub

How can I fix this issue





Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>