'Button_Click':不是'ButtonTest :: MainPage'的成员 [英] 'Button_Click' : is not a member of 'ButtonTest::MainPage'
问题描述
我是C ++和Windows商店编程的新手,我坚持在按钮上定义点击处理程序。我指的是这些说明:
I'm new to C++ and Windows Store programming, and I'm stuck defining click handlers on buttons. I'm referring to these instructions:
- 将Button控件添加到父容器。
- 要为按钮分配名称,请将x:Name属性设置为字符串值。要在代码中引用控件,它必须有一个名称。
- 要为按钮分配标签,请将Content属性设置为字符串值。
- >要在用户单击按钮时执行操作,请为Click事件添加处理程序。在Click事件处理程序中,添加执行
操作的代码。
- 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 =button1Content =Button
Click =Button_Click/>
void MainPage :: Button_Click(Object ^ sender,RoutedEventArgs ^ e){
p>
//添加代码以在此处执行某些操作。
}
void MainPage::Button_Click(Object^ sender, RoutedEventArgs^ e) {
// Add code to perform some action here.
}
- 我已添加了
< Button x:Name =button1 =
中的
块中<= c $ c =>ButtonClick =Button_Click/>
$ c>。 - 我添加了
void MainPage :: Button_Click(Object ^ sender,RoutedEventArgs ^ e){...}
MainPage.xaml.cpp
。 - I've added the
<Button x:Name="button1" Content="Button" Click="Button_Click" />
inside theGrid
block inMainPage.xaml
. - I've added
void MainPage::Button_Click(Object^ sender, RoutedEventArgs^ e) {...}
inMainPage.xaml.cpp
.
我不能解决:
错误C2039:'Button_Click':不是'ButtonTest :: MainPage'的成员
error C2039: 'Button_Click' : is not a member of 'ButtonTest::MainPage'
和
IntelliSense:classButtonTest :: MainPage没有成员Button_Click
IntelliSense: class "ButtonTest::MainPage" has no member "Button_Click"
我如何解决这个问题?
推荐答案
您将需要在 MainPage.xaml.h中定义
文件作为类的成员。喜欢 MainPage :: Button_Click
的原型
You will need to define the prototype of MainPage::Button_Click
in the MainPage.xaml.h
file as a member of the class. Like
public:
Button_Click(object^, RoutedEventArgs^);
C ++每个方法都需要一个原型。
C++ needs a prototype for every method.
这篇关于'Button_Click':不是'ButtonTest :: MainPage'的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!