XAML Textbox Problem for XAML.cs

0

I have a XAML (Cadastro.xaml) where I made a TextBox and a PasswordBox and named them as txtCpf and txtSenha , until then without any problem.

When I'm going to use them in Cadastro.xaml.cs , I can not and the error appears saying:

  

"The name does not exist in the current context"

How do I declare in .cs the two TextBox ?

    
asked by anonymous 26.06.2018 / 05:13

1 answer

0

You may have declared the components wrong.

Below is the correct way to name your components, using the x:Name :

<TextBox x:Name="txtCpf" HorizontalAlignment="Left" Height="23" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<PasswordBox x:Name="txtSenha" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120"/>

And in the code you can access them as follows:

string cpg = txtCpf.Text;
string password = txtSenha.Password;
    
26.06.2018 / 14:24