'Button_Click':不是'ButtonTest :: MainPage'的成员 [英] 'Button_Click' : is not a member of 'ButtonTest::MainPage'

查看:203
本文介绍了'Button_Click':不是'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:



  1. 将Button控件添加到父容器。

  2. 要为按钮分配名称,请将x:Name属性设置为字符串值。要在代码中引用控件,它必须有一个名称。

  3. 要为按钮分配标签,请将Content属性设置为字符串值。

  4. >要在用户单击按钮时执行操作,请为Click事件添加处理程序。在Click事件处理程序中,添加执行
    操作的代码。

  1. Add a Button control to a parent container.
  2. 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.
  3. To assign a label to the button, set the Content property to a string value.
  4. 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 the Grid block in MainPage.xaml.
    • I've added void MainPage::Button_Click(Object^ sender, RoutedEventArgs^ e) {...} in MainPage.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆