模板化用户控件标记的 Intellisense

Intellisense for Templated User Control Tags

提问人:Kevin 提问时间:12/21/2011 最后编辑:CommunityKevin 更新时间:6/26/2014 访问量:794

问:

我编写了一个模板化用户控件 MinimalTemplate,它目前除了呈现传递到其“ContentTemplate”占位符中的 HTML 外,什么都不做。我希望 Visual Studio 2008 具有与内置模板化控件(如 Repeater)相同的 MinimalTemplate 智能感知功能。

enter image description here

enter image description here

可能相关:我可以手动输入我的 ContentTemplate 标签,它将正确构建和运行,但我收到验证错误。我已经删除了 ReflectedSchemas 文件夹的内容,如本问题所示。

enter image description here

最小模板的完整来源:

MinimalTemplate.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MinimalTemplate.ascx.cs" Inherits="MyProject.MinimalTemplate" %>
<asp:placeholder runat=server id="contentPlaceHolder" />

最小模板.ascx.cs

using System.Web.UI;

namespace MyProject
{
    [ParseChildren(false)]
    public partial class MinimalTemplate : System.Web.UI.UserControl
    {

        [TemplateContainer(typeof(MessageContainer))]
        [TemplateInstance(TemplateInstance.Single)]
        public ITemplate ContentTemplate
        { get; set; }

        void Page_Init()
        {
            if (ContentTemplate != null)
            {
                MessageContainer container = new MessageContainer();
                ContentTemplate.InstantiateIn(container);
                contentPlaceHolder.Controls.Add(container);
            }
        }

        public class MessageContainer : Control, INamingContainer { }
    }
}

我可以对 MinimalTemplate 代码进行哪些更改,以便 Visual Studio 验证并自动完成其 ContentTemplate 标记?

asp.net visual-studio-2008

评论


答:

0赞 Kevin 12/29/2011 #1

相关

添加到 ContentTemplate 的属性列表。添加并重新生成后,验证错误消失,并且“ContentTemplate”按预期显示在 Intellisense 下拉列表中。[PersistenceMode(PersistenceMode.InnerProperty)]

在我的调查过程中,我确定我尝试添加此属性两到三次都没有效果,所以我预计 VS 验证器有点不稳定。它有点像巫毒教编程,但请执行“全部清理/重建”并等待几秒钟,然后再查看验证错误是否仍然存在。

(此外,此控件不需要 ParseChildren 属性。