You need something like that. Everything is fine, but you need to populate the TabCollection class.
Edit: Excuse me, I have not tested the code. In any case, some problems have been resolved.
Usercontrol
[ParseChildren(true, "Tabs"), PersistChildren(false)]
public partial class TabMenu : UserControl
{
private TabCollection _tabs;
[Browsable(false), PersistenceMode(PersistenceMode.InnerProperty), MergableProperty(false)]
public virtual TabCollection Tabs
{
get
{
if (this._tabs == null)
this._tabs = new TabCollection(this);
return this._tabs;
}
}
protected override ControlCollection CreateControlCollection()
{
return new TabMenuControlCollection(this);
}
}
Tab
public class Tab : HtmlGenericControl
{
public string Label
{
get { return (string)ViewState["Label"] ?? string.Empty; }
set { ViewState["Label"] = value; }
}
}
Tabcollection
public class TabCollection : IList, ICollection, IEnumerable
{
private TabMenu _tabMenu;
public TabCollection(TabMenu tabMenu)
{
if (tabMenu == null)
throw new ArgumentNullException("tabMenu");
this._tabMenu = tabMenu;
}
public virtual int Add(Tab tab)
{
if (tab == null)
throw new ArgumentNullException("tab");
this._tabMenu.Controls.Add(tab);
return this._tabMenu.Controls.Count - 1;
}
int IList.Add(object value)
{
return this.Add((Tab)value);
}
}
TabMenuControlCollection
public class TabMenuControlCollection : ControlCollection
{
public TabMenuControlCollection(TabMenu owner) : base(owner) { }
public override void Add(Control child)
{
if (child == null)
throw new ArgumentNullException("child");
if (!(child is TabMenu))
throw new ArgumentException("The TabMenu control can only have a child of type 'Tab'.");
base.Add(child);
}
public override void AddAt(int index, Control child)
{
if (child == null)
throw new ArgumentNullException("child");
if (!(child is TabMenu))
throw new ArgumentException("The TabMenu control can only have a child of type 'Tab'.");
base.AddAt(index, child);
}
}
source
share