How to do this in WPF?

-1

Textbox:

 <TextBox x:Name="tbSearch" Margin="18,48.999,888,0" Width="200" Background="#FF740587" HorizontalAlignment="Left" FontSize="16" FontFamily="Arial" Height="25" VerticalAlignment="Top" Grid.Column="1" Text="Search" Foreground="Moccasin" Visibility="Hidden"/>

What I need is to shift the focus to this textbox and change the Visibility of it. What I did in VB was:

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If textbox1.Visible = False Then
        textbox1.Visible = True
        textbox1.Text = Nothing
        textbox1.Control.Select()
    Else
        textbox1.Visible = False
        textbox1.Text = Nothing
    End If
End Sub

This gave me the focus on textbox1 , but I can not do that in WPF. I already tried:

tbSearch.Focusable = True
FocusManager.SetFocusedElement(FocusManager.GetFocusScope(tbSearch), tbSearch)


tbSearch.Focusable = True
tbSearch.Focus()


tbSearch.Focusable = True
Keyboard.Focus(tbSearch)

Visibility.

tbSearch.Visibility = Visibility.Hidden

So how can I do this?

    
asked by anonymous 30.12.2018 / 23:38

0 answers