Missing Intellisense While Describing Custom Control Properties Declaratively

时间秒杀一切 提交于 2019-12-20 01:07:40

问题


So, I've been working on this project for a few days now, and have been unable to resolve the issue of getting intellisense support for my custom-defined inner properties for a user control (ascx, mind you).

I have seen the solution to this (using server controls, .cs mind you) many times. Spelled out in this article very well. Everything works for me while using ascx controls except intellisense.

Here's the outline of my code:

[PersistChildren(true)]
[ParseChildren(typeof(BreadCrumbItem))]
[ControlBuilder(typeof(BreadCrumbItem))]
public partial class styledcontrols_buttons_BreadCrumb : System.Web.UI.UserControl
{
    ...

    [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    public List<BreadCrumbItem> BreadCrumbItems
    {
        get { return _breadCrumbItems; }
        set { _breadCrumbItems = value; }
    }

    ...

    protected override void AddParsedSubObject(object obj)
    {
            base.AddParsedSubObject(obj);
            if (obj is BreadCrumbItem)
                    BreadCrumbItems.Add(obj as BreadCrumbItem);
    }

    ...

    public class BreadCrumbItem : ControlBuilder
    {
        public string Text { get; set; }
        public string NavigateURL { get; set; }

        public override Type GetChildControlType(string tagName, System.Collections.IDictionary attribs)
        {
            if (String.Compare(tagName, "BreadCrumbItem", true) == 0)
            {
                return typeof(BreadCrumbItem);
            }
            return null;
        }
    }
}

Here's my mark up (which works fine, just no intellisense on the child object declarations):

<%@ Register src="../styledcontrols/buttons/BreadCrumb.ascx" tagname="BreadCrumb" tagprefix="uc1" %>

    ...

<uc1:BreadCrumb ID="BreadCrumb1" runat="server" BreadCrumbTitleText="Current Page">
    <BreadCrumbItem Text="Home Page" NavigateURL="~/test/breadcrumbtest.aspx?iwentsomewhere=1" />
    <BreadCrumbItem Text="Secondary Page" NavigateURL="~/test/breadcrumbtest.aspx?iwentsomewhere=1" />
</uc1:BreadCrumb>

I think the issue lies with how the intellisense engine traverses supporting classes. All the working examples I see of this are not ascx, but Web Server Controls (cs, in a compiled assembly).

If anyone could shed some light on how to accomplish this with ascx controls, I'd appreciate it.


回答1:


I have solved this before by removing all the user controls and directives from the page and then switching the markup to design view. You then drag the ascx file from the solution explorer to the design window. If you swich back to markup view suddenly intelisense picks up all the properties. I am sure there is a better way but i have never found one that works.



来源:https://stackoverflow.com/questions/2885832/missing-intellisense-while-describing-custom-control-properties-declaratively

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!