windows-runtime - 是否可以在 Windows 运行时为 Windows Phone 创建一个未密封的基引用类?

标签 windows-runtime windows-phone-8 c++-cx

是否可以在 Windows 运行时的 Windows Phone 8 变体中创建一个基类,供其他公共(public)引用类使用?

对于 Windows 应用商店应用 MSDN documents a way to do this (见下文)。

然而,这依赖于将 Windows::UI::Xaml::DependencyObject 作为允许的未密封基类。

由于 Windows Phone 8 没有 C++/XAML 编程功能,因此此类不可用。您不得创建在公共(public) ref 类中可见的顶级对象,因为这会发出编译器警告。

是否有另一个合适的基类可以在 Windows Phone 8 中用来代替 Windows::UI::Xaml::DependencyObject

namespace InheritanceTest2 
{
    namespace WFM = Windows::Foundation::Metadata;

    // Base class. No public constructor.
    [WFM::WebHostHidden]
    public ref class Base : Windows::UI::Xaml::DependencyObject 
       // DependencyObject NOT AVAILABLE ON WP8!
    {
    internal:
        Base(){}
    protected:
        virtual void DoSomething (){}
        property Windows::UI::Xaml::DependencyProperty^ WidthProperty;
};

// Class intended for use by client code across ABI.
// Declared as sealed with public constructor.
public ref class MyPublicClass sealed : Base
{
public:
    MyPublicClass(){}
    //...
};

最佳答案

http://channel9.msdn.com/Events/Build/2012/3-049

WinRT doesn't really support the notion of inheritance for classes. A special case is made for XAML controls in Windows 8, but we don't support C++ XAML on Windows Phone 8.

Peter Torr (MSFT)

关于windows-runtime - 是否可以在 Windows 运行时为 Windows Phone 创建一个未密封的基引用类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15296230/

相关文章:

c# - 如何防止在数据绑定(bind)时自动选择 GridView 中的第一项?

uwp - 如何将字节复制到 Windows::Storage::Streams::Buffer 或 Buffer 以通过 Windows::Storage::Streams::DataWriter::Write Buffer() 输出

c++ - UWP : WACK test failing on Windows Runtime metadata validation

c++ - 如何在 C++/CX 中使用具有属性的类创建复制构造函数

c# - 为什么将 XAML 图像源设置为 URI 比使用 HttpClient 获取图像更快?

ios - Metro 风格应用程序是否可移植到 iphone 和 ipad 以及 Web 应用程序?

visual-studio-2012 - 在 WP8 设备上调试时 XAML 未更新

windows-phone-8 - 使用 Windows 8 电话自动调用电话号码

c# - Windows 8 用户控件示例

c# - 如何在WP8中创建Excel文件?