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

1

8

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?
Windproof answered 3/10, 2012 at 16:50 Comment(0)
N
15

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.

Nf answered 3/10, 2012 at 17:3 Comment(1)
Are there other use cases, except from user authored control, which require this attribute ? for example, suppose I've C++/Cx component not dealing w/ UI at all, under which circumstances one should annotate this component w/ WebHostHidden ?Prenotion

© 2022 - 2024 — McMap. All rights reserved.