windowsxamluwpc++-cx

Can't change textbox text XAML, C++/CX: Undeclared Identifier


I need to be able to update the text in a XAML TextBox element when a button is clicked. I was able to do this with the example Hello World application on Microsoft's website with no issues, but when I attempt it now doing the exact same thing, I'm getting an undeclared identifier error on the text box.

This is my XAML code:

<Button Background="Black" Content="This is a Button" Width="400" Height="100" Click="Button_Click"/>
<TextBox Grid.Column="1" x:Name="textBox"/>

This is my C++ code:

void Sentinel::VisualizePage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) {   
    textBox->Text = "Hi";
}

And here's the error:
1
I don't understand how this exact same code was working for the hello world project, but is not working for this user control.


Solution

  • In your defense, it was a tough one. Check the auto-generated files. There should be one titled something like: .g.h. There will be element definitions there. Be sure your element is listed there, then try again.

    It should be something along the lines of:

    private: ::Windows::UI::Xaml::Controls::TextBox^ textBox;