Problem in the XAML Textbox for XAML.Cs

Asked

Viewed 44 times

0

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

When I’m gonna use them on Cadastro.xaml.cs, I can not and appears the error saying that:

"the name does not exist in the current context"

How do I declare in .cs both TextBox?

  • It happened cmg, I just reset the VS.

1 answer

0

Maybe I declared the components wrong.

Below follows the correct way to name your components, using the property 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;
  • The problem was in "x:Name="txtCpf"". I didn’t have it in mine. Thanks, man!!!

  • If the answer helped you, mark it as correct to help other people with the same problem!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.