protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding) { if (this.itemsArray != null) { this.itemsArray.Clear(); } else { this.itemsArray = new ArrayList(); } if (!dataBinding) { int dataItemCount = System.Convert.ToInt32(ViewState["_!ItemCount"]); dataSource = new Data.DummyDataSource(dataItemCount); this.itemsArray.Capacity = dataItemCount; } else if (dataSource == null) { return(0); } Panel leftSliding = CreateLeftSliding(); Panel rightSliding = CreateRightSliding(); Unit width = Unit.Parse("0px"); if (leftSliding.Width.Type == UnitType.Pixel && rightSliding.Width.Type == UnitType.Pixel) { if (this.Width.IsEmpty) { width = Unit.Parse(DefaultWidth); width = new Unit(width.Value - leftSliding.Width.Value - rightSliding.Width.Value, UnitType.Pixel); } else if (width.Type == UnitType.Pixel) { width = new Unit(this.Width.Value - leftSliding.Width.Value - rightSliding.Width.Value, UnitType.Pixel); } } if (width.Value <= 0) { throw (new InvalidOperationException("Control, LeftSliding, and RightSliding styles must use the Pixel unit on its width")); } Panel centerPanel = CreateCenterPanel(width); Controls.Add(leftSliding); Controls.Add(centerPanel); Controls.Add(rightSliding); Panel content = new Panel(); content.ID = "container"; content.Height = Unit.Parse("100%"); content.Style["position"] = "relative"; content.Style["left"] = "0px"; centerPanel.Style["position"] = "relative"; centerPanel.Controls.Add(content); //adding items to the centerpanel. int indice = 0; /* * Dim itens As New List(Of SlidingPanelItem) */ foreach (object obj in dataSource) { ListItemType tipo = ListItemType.Item; if (indice % 2 != 0) { tipo = ListItemType.AlternatingItem; } SlidingPanelItem item = new SlidingPanelItem(indice, tipo); itemsArray.Add(item); Style style = new Style(); if (tipo == ListItemType.AlternatingItem) { if (this.AlternatingItemTemplate != null) { AlternatingItemTemplate.InstantiateIn(item); } else if (this.ItemTemplate != null) { ItemTemplate.InstantiateIn(item); } if ((AlternatingItemStyle != null) && !AlternatingItemStyle.IsEmpty) { style = AlternatingItemStyle; } else { style = ItemStyle; } } else if (tipo == ListItemType.Item) { if (this.ItemTemplate != null) { ItemTemplate.InstantiateIn(item); } style = ItemStyle; } SlidingPanelItemEventArgs e = new SlidingPanelItemEventArgs(item); OnItemCreated(e); content.Controls.Add(item); if (dataBinding) { item.SetDataItem(obj); item.DataBind(); OnItemDataBound(e); item.SetDataItem(null); } item.SetStyle(style); indice++; } int itensCount = itemsArray.Count; if (itensCount > 4) { itensCount = 4; } Unit defaultItemWidth = ItemStyle.Width; if (defaultItemWidth.IsEmpty) { defaultItemWidth = Unit.Parse(Math.Round(centerPanel.Width.Value / itensCount).ToString() + "px"); } foreach (SlidingPanelItem i in itemsArray) { if (i.Width.IsEmpty) { i.Width = defaultItemWidth; } if (this.DesignMode) { int indiceItem = itemsArray.IndexOf(i) + 1; int rightPixel = (int)(defaultItemWidth.Value * indiceItem); if (rightPixel >= centerPanel.Width.Value) { content.Controls.Remove(i); } } } int offset = MovingOffset; if (offset == 0) { offset = (int)defaultItemWidth.Value; } SetAction(leftSliding, +offset, (int)centerPanel.Width.Value); SetAction(rightSliding, -offset, (int)centerPanel.Width.Value); if (dataBinding) { ViewState["_!ItemCount"] = itemsArray.Count; } SendScripts(); return(itemsArray.Count); }