Itemplate 属性不可用作属性
我已向 Telerik 的 RadGrid 控件添加了一个名为 SearchMenuTemplate 的 ITemplate:
public class AbsRadGrid : RadGrid
{
private ITemplate _ItemTemplate;
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(searchBar))]
public ITemplate SearchMenuTemplate
{
get { return _ItemTemplate; }// get
set { _ItemTemplate = value; }// set
}
}
并且 Template 类看起来类似于(为简洁起见,已省略像 createchildcontrol 这样的强制重写方法):
[ParseChildren(true)]
class searchBar : CompositeControl, INamingContainer
{
public string rbStartsWithText { get; set; }
}
现在,在源代码管理窗口中,RadGrid 控件可以看到模板。但 rbStartsWithText 不是节点上的属性。
我想看到这样的东西(注意:abs 前缀在标记中注册):
<abs:AbsRadGrid ID="rg" runat="server">
<SearchMenuTemplate rbStartsWithText="Starts With" />
</abs:AbsRadGrid>
相反,rbStartsWithText 抛出一个绿色的波浪线并告诉我它不是 SearchMenuTemplate 的有效属性。
I've added an ITemplate to Telerik's RadGrid control called SearchMenuTemplate ala:
public class AbsRadGrid : RadGrid
{
private ITemplate _ItemTemplate;
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(searchBar))]
public ITemplate SearchMenuTemplate
{
get { return _ItemTemplate; }// get
set { _ItemTemplate = value; }// set
}
}
And the Template class looks something like (mandatory override methods like createchildcontrol have been omitted for brevity):
[ParseChildren(true)]
class searchBar : CompositeControl, INamingContainer
{
public string rbStartsWithText { get; set; }
}
Now, in the source control window the RadGrid control sees the Template. But rbStartsWithText isn't an attribute on the node.
I want to see something like this (note: abs prefix is registered in the markup):
<abs:AbsRadGrid ID="rg" runat="server">
<SearchMenuTemplate rbStartsWithText="Starts With" />
</abs:AbsRadGrid>
Instead rbStartsWithText is throwing a green squiggly and telling me it's not a valid attribute of SearchMenuTemplate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
SearchMenuTemplate
属性属于ITemplate
类型,没有公共属性,因此 IntelliSense 无法为您的
标记提供任何属性。为了能够添加自定义属性,您应该实现
ITemplate
接口(InstantiateIn
方法)并在其中添加所需的属性:然后您可以在自定义网格中使用它:
最后:
Your
SearchMenuTemplate
property is of a typeITemplate
which hasn't public properties, so IntelliSense just cannot offer any attribute for your<SearchMenuTemplate>
tag.To be able to add a custom property you should implement
ITemplate
interface (InstantiateIn
method) and add desired property there:then you could use it your custom grid:
and finally: