Jack Detrick
Jack Detrick

Reputation: 67

C++/winRT xaml Keyboard Event handler

The following, when compiled, produces a "1 unresolved externals..." My question is - what are the proper parameters?

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

pragma once

include "MainPage.g.h"

namespace 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);
}; }

namespace 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) {

    }


}

I changed the handlers (,h & ,cpp) to the following and problem exists: void Keyboard_KeyDown(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e);

2018-1207 - included this in the .h file

include

Upvotes: 0

Views: 580

Answers (1)

Jack Detrick
Jack Detrick

Reputation: 67

This was missing in the .H file

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

Upvotes: 1

Related Questions