【问题标题】:How can I override method using C++/CX?如何使用 C++/CX 覆盖方法?
【发布时间】:2020-05-11 15:12:42
【问题描述】:

我正在尝试覆盖 CommandBar 的 OnKeyDown 方法:

public ref class myCommandBar: public CommandBar {
protected:
    virtual void OnKeyDown(KeyRoutedEventArgs e);
};

但我收到错误:

错误 C3992:“OnKeyDown”:公共成员的签名包含无效类型“Windows::UI::Xaml::Input::KeyRoutedEventArgs”

【问题讨论】:

    标签: xaml uwp c++-cx


    【解决方案1】:

    KeyRoutedEventArgs 通过引用而不是值传递。签名应该是这样的:

    virtual void OnKeyDown(KeyRoutedEventArgs^ e);
    

    【讨论】:

    • 谢谢。我还必须将类标记为已密封才能在 XAML 中使用。而且我必须在方法声明中添加“覆盖”。
    猜你喜欢
    • 2010-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    相关资源
    最近更新 更多