Hi!
I've build an simple control called Menu:
namespace MyControls
{
public class MenuItem
{
public MenuItem()
{
Visible = true;
}
[Localizable(true)]
public string Text { get; set; }
[Localizable(false)]
public string Link { get; set; }
[DefaultValue(true)]
public bool Visible { get; set; }
}
public class MenuDesigner : System.Web.UI.Design.ControlDesigner
{
...
}
[ParseChildren(true, "Items")]
[PersistChildren(false)]
[Designer(typeof(MenuDesigner))]
public class Menu : Control
{
...
public Menu()
{
}
...
private List<MenuItem> _items = new List<MenuItem>();
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<MenuItem> Items
{
get
{
return _items;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
... // More Controls.
list = new BulletedList();
list.DisplayMode = BulletedListDisplayMode.HyperLink;
this.Controls.Add(list);
foreach (var mi in _items)
{
list.Items.Add(new ListItem(mi.Text, Page.Request.CreateUrl(mi.Link)));
}
}
}
}
I use it in my Page this way:
<my:Menu ID="menu" runat="server" Text="MenuTitle">
<my:MenuItem Text="text" Link="link1.aspx">
</my:MenuItem>
<my:MenuItem Text="text2" Link="link2.aspx">
</my:MenuItem>
</my:Menu>
This works. No Problems. When I switch to the Designer View I see the Control in the way my MenuDesigner renders it. Reformating with CTRL-K, CTRL-D works. Running my WebPage renders to Menu the way I expected it.
But: when I hit in the DesingView the Menu Item "Tools" -> "Generate Local Resource" I get this result:
<my:Menu ID="menu" runat="server" Text="MenuTitle"
meta:resourcekey="menuResource9">
<my:MenuItem Text="text" Link="link1.aspx">
</my:MenuItem>
<my:MenuItem Text="text2" Link="link2.aspx">
</my:MenuItem>
<Items>
<my:MenuItem Text="text" Link="link1.aspx" meta:resourcekey="MenuItemResource10"></my:MenuItem>
<my:MenuItem Text="text2" Link="link2.aspx" meta:resourcekey="MenuItemResource11"></my:MenuItem>
</Items>
</my:Menu>
Which Attributes are missing/wrong? I've looked into ListBox, which also parses child items an I have the feelding that my control is doing the same.
The only differences I've found:
- I am using a generic List, ListBox has it's own collection type for ListItems
- I have no Editor or ControlBuilder or TypeConverter for my MenuItem, ListBox does.
This is not a control I'm willing to sell, it's only for me. I don't need any Editor or Desinger, I'm writing HTML/ASP.NET markup by hand.
I am using Visual Studio 2008, .NET 3.5.
Thanks for any Hints, Help or Sulutions!