为什么在自定义 WinRT C++/CX 控件中默认添加了 [Windows::Foundation::Metadata::WebHostHidden]? [英] Why is [Windows::Foundation::Metadata::WebHostHidden] added by default in custom WinRT C++/CX controls?
问题描述
当我在 WinRT C++/CX 项目中创建新控件时,Visual Studio 2012 默认添加了类属性 [Windows::Foundation::Metadata::WebHostHidden]
.>
示例:
命名空间 WindowsRuntimeComponent1{[Windows::Foundation::Metadata::WebHostHidden]公共引用类 MyUserControl 密封{民众:我的用户控制();};}
- 是否有任何记录在案的原因?(我做了作业,但我未能找到这条信息)
- 据我所知,使用属性
[WebHostHidden]
使类对于 WinRT HTML/Javascript 项目不可见.这是否意味着我无法在 C++/CX 中创建可以在 Javascript 中使用的控件?
据我所知,使用属性
[WebHostHidden]
使该类对于 WinRT HTML/JavaScript 项目不可见.
这是正确的:此属性在 JavaScript 投影中隐藏了类型,因此从 JavaScript 看来,该类型似乎不存在.
<块引用>这是否意味着我无法在 C++/CX 中创建可以在 JavaScript 中使用的控件?
您不能使用 JavaScript 中的 XAML 控件,句号.使用 JavaScript 时,UI 是使用 HTML 而不是 XAML 创作的.
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?
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.
这篇关于为什么在自定义 WinRT C++/CX 控件中默认添加了 [Windows::Foundation::Metadata::WebHostHidden]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!