Why is [Windows::Foundation::Metadata::WebHostHidden] added by default in custom WinRT C++/CX controls?

江枫思渺然 提交于 2019-12-08 17:35:52

问题


When I create a new control in a WinRT C++/CX project, the class attribute [Windows::Foundation::Metadata::WebHostHidden] is added by default by Visual Studio 2012.

Example:

namespace WindowsRuntimeComponent1
{
    [Windows::Foundation::Metadata::WebHostHidden]
    public ref class MyUserControl sealed
    {
    public:
        MyUserControl();
    };
}
  • Is there any documented reason for this? (I did my homework but I failed to find this piece of information)
  • As far as I know, using the attribute [WebHostHidden] makes the class invisible for WinRT HTML/Javascript projects. Does this mean that I cannot create a control in C++/CX that can be used in Javascript?

回答1:


As far as I know, using the attribute [WebHostHidden] makes the class invisible for WinRT HTML/JavaScript projects.

This is correct: this attribute hides the type in the JavaScript projection, so from JavaScript it is as if the type does not exist.

Does this mean that I cannot create a control in C++/CX that can be used in JavaScript?

You cannot use XAML controls from JavaScript, period. When using JavaScript, UI is authored using HTML, not XAML.



来源:https://stackoverflow.com/questions/12713143/why-is-windowsfoundationmetadatawebhosthidden-added-by-default-in-custom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!