绑定资源数据到自定义winjs控件
问题描述:
我想创建一个自定义占位符控件。下面是代码摘录:绑定资源数据到自定义winjs控件
(function() {
var Placeholder = WinJS.Class.define(function ctor(elem, options) {
this.element = elem || document.createElement('div');
this.element.winControl = this;
WinJS.UI.setOptions(this, options);
this.init();
},
{
element: {
get: function() {
return this._element;
},
set: function (value) {
this._element = value;
}
},
placeholder: {
get: function() {
return this._placeholder;
},
set: function (value) {
this._placeholder = value;
this._placeholderElement.textContent = value;
}
},
placeholderClass: {
get: function() {
return this._placeholderClass;
},
set: function (value) {
this._placeholderClass = value;
this._placeholderElement.classList.add(value);
}
},
_placeholderElement: null,
init: function() {
this._addPlaceholder();
},
_addPlaceholder: function() {
/* Code to add placeholder. */
}
});
WinJS.Namespace.define("ControlX", { Placeholder: Placeholder });
})();
我想以这种方式来使用此控件的HTML:
<div data-win-control="ControlX.Placeholder" data-win-res="{winControl:{placeholder:'resHeight'}}"><input type="text"/></div>
当我使用data-win-res
属性设置占位符值,我得到一个异常:
“无法设置的未定义或空引用属性 '占位符'”
根据这篇文章: How to localize WinJS controls我们也可以将资源字符串绑定到winControl属性。
我在做什么错?
是否有任何其他方式绑定资源字符串到winControl属性?
答
我正在开发Windows 8的应用程序在C#& XAML,所以不知道是什么确切的解决方案,但我认为这个答复可能的工作:
我建议,而不是创建内部类和定义只是方法参数,每种方法和类都应该被分开,并在一种方法中与该全新定制WinJS控件的适当名称相结合。 在给出该控件的名称后,您应该通过DIV标记中的名称来调用该控件。
我不是很强大,并且用它的代码进行实践,最好不要提供代码,对此感到抱歉。但我相信,通过这个名字给人的名字,并要求将有助于 所有最好的...
(对不起,如果你认为这是不是给你答案。但我认为这可能帮助)
您是否在页面控制中进行控制?如果是这样,你是否在PageControls的ready函数中调用了WinJS.Resources.processAll(element)?我似乎能够得到这个工作,但我不能说出我们两个努力之间可能会有什么不同。 – 2013-02-19 02:15:31