我是 C++ 和 Windows 应用商店编程的新手,我一直在定义按钮上的点击处理程序。我指的是 these说明:
- Add a Button control to a parent container.
- To assign a name to the button, set the x:Name attribute to a string value. To refer to a control in code, it must have a name. Otherwise, a name is not required.
- To assign a label to the button, set the Content property to a string value.
- To perform an action when a user clicks the button, add a handler for the Click event. In the Click event handler, add code to perform some action.
<Button x:Name="button1" Content="Button" Click="Button_Click" />
void MainPage::Button_Click(Object^ sender, RoutedEventArgs^ e) {<br/> // Add code to perform some action here.<br/> }
- 我添加了
<Button x:Name="button1" Content="Button" Click="Button_Click" />
在Grid
里面阻止MainPage.xaml
. - 我添加了
void MainPage::Button_Click(Object^ sender, RoutedEventArgs^ e) {...}
在MainPage.xaml.cpp
.
现在我遇到两个错误,我无法解决:
error C2039: 'Button_Click' : is not a member of 'ButtonTest::MainPage'
和
IntelliSense: class "ButtonTest::MainPage" has no member "Button_Click"
我该如何解决这个问题?
最佳答案
您需要在 MainPage.xaml.h
文件中将 MainPage::Button_Click
的原型(prototype)定义为该类的成员。喜欢
public:
Button_Click(object^, RoutedEventArgs^);
C++ 需要每个方法的原型(prototype)。
关于c++ - 'Button_Click' : is not a member of 'ButtonTest::MainPage' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15888991/