根据此页面https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/binding-property
我正在编写以下代码
/*cl /nologo /Yupch.h /bigobj /await /std:c++latest /EHsc /I. demo.cpp pch.obj /link /winmd /out:appx\App.exe /subsystem:console /appcontainer*/
struct MainPage : PageT<MainPage>
{
MainPage()
{
Application::LoadComponent(*this, Uri(L"ms-appx:///MainPage.xaml"));
}
void ClickHandler(Windows::Foundation::IInspectable const& /* sender */, Windows::UI::Xaml::RoutedEventArgs const& /* args */)
{
cout << __func__ << endl;
}
};MainPage.xaml页面如下所示
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Button Click="ClickHandler">click</Button>
</Page>但是看起来MainPage::ClickHandler从来没有被调用过,那么,正确的方式是什么呢?非常感谢!
发布于 2019-12-01 20:59:54
您的MainPage.xaml在根Page声明中缺少x:Class attribute:
<Page x:Class="MyNamespace.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Button Click="ClickHandler">click</Button>
</Page>如果没有该属性,XAML平台就不知道在哪里查找绑定到Click事件的ClickHandler。
https://stackoverflow.com/questions/59124778
复制相似问题