C ++ / winRT xaml键盘事件处理程序

时间:2018-11-29 14:11:54

标签: c++-winrt

以下内容在编译时会产生“ 1个未解决的外部...” 我的问题是-正确的参数是什么?

using namespace winrt;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Input;

xaml
KeyDown="Keyboard_keyDown"

 .h
 void Keyboard_keyDown(Windows::Foundation::IInspectable const& sender, 
   Windows::UI::Xaml::Input::KeyRoutedEventArgs e);

 .cpp
 void SettingsPage::Keyboard_keyDown(IInspectable const& sender,
Windows::UI::Xaml::Input::KeyRoutedEventArgs e) {...}

MainPage.xaml

<Page
x:Class="BlankAppKeypaderror.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:BlankAppKeypaderror"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"

KeyDown="Keyboard_keyDown"

>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
    <Button x:Name="myButton" Click="ClickHandler">Click Me</Button>
</StackPanel>

  

MainPage.h

     

一次编译

     

包括“ MainPage.g.h”

     

命名空间winrt :: DemoProblemApp :: implementation {       struct MainPage:MainPageT       {           MainPage();

    int32_t MyProperty();
    void MyProperty(int32_t value);
    void Keyboard_keyDown(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs e);
    void ClickHandler(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
}; }
     

命名空间winrt :: DemoProblemApp :: factory_implementation {       struct MainPage:MainPageT       {       }; }

MainPage.cpp

    #include "pch.h"
#include "MainPage.h"

using namespace winrt;
using namespace Windows::UI::Xaml;

namespace winrt::DemoProblemApp::implementation {
    MainPage::MainPage() {
        InitializeComponent();
    }

    int32_t MainPage::MyProperty() {
        throw hresult_not_implemented();
    }

    void MainPage::MyProperty(int32_t /* value */) {
        throw hresult_not_implemented();
    }

    void MainPage::ClickHandler(IInspectable const&, RoutedEventArgs   const&) {
        myButton().Content(box_value(L"Clicked"));
    }

    void MainPage::Keyboard_keyDown(Windows::Foundation::IInspectable     const& sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs e) {

    }


}

我将处理程序(,h&,cpp)更改为以下内容,并且存在问题:         void Keyboard_KeyDown(Windows :: Foundation :: IInspectable const&sender,Windows :: UI :: Xaml :: Input :: KeyRoutedEventArgs const&e);

2018-1207-将其包含在.h文件中

包括

1 个答案:

答案 0 :(得分:0)

.H文件中缺少此内容

#include <winrt/Windows.UI.Xaml.Input.h>