gpt4 book ai didi

c++ - 'Button_Click' : is not a member of 'ButtonTest::MainPage'

转载 作者:行者123 更新时间:2023-11-28 03:19:24 26 4
gpt4 key购买 nike

我是 C++ 和 Windows 应用商店编程的新手,我一直在定义按钮上的点击处理程序。我指的是 these说明:

  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="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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com