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

标签 c++ windows windows-store-apps

我是 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/

相关文章:

c++ - vkCreateSwapchainKHR() : surface capabilities not retrieved for this physical device

windows-8 - 使用 Peerfinder 是否需要 NFC?

c# - 如何在 Windows 应用商店应用程序中将内容剪辑为椭圆

c++ - 如何在 STL 中使用 libclang?

c++ - 使用 Cygwin boost asio 错误

c# - C++ 到 C#,C# 到带有外部 DLL 的 C++,DLL 未找到异常

memory-management - 商店应用内存管理

c++ - window C++ |写入文件时,什么负责将\n 转换为\r\n?

mysql - 从 cmd 窗口获取上一个显示的输出

linux - 如何在 ubuntu bash 中访问 Windows 目录