public void AddChild(UIEvent E)
 {
     UIEvents.Add(E);
     this.hasEvent = true;
     if (this.Mode == ModeOfTime.HOUR)
     {
         this.UIContent.Children.Add(E);
     }
     else
     {
         double tmpTop = 0;
         foreach (UIElement uiE in this.UIContentScroll.Children)
         {
             tmpTop = uiE.getTop() +(double) uiE.GetValue(HeightProperty);
         }
         E.setTop(tmpTop + 2);
         this.UIContentScroll.Children.Add(E);
         UIContentScroll.Height = tmpTop + 2 + E.Height;
     }
 }
 public void RemoveChild(UIEvent E)
 {
     foreach (UIElement uiE in this.UIContent.Children)
     {
         if (uiE is UIEvent)
         {
             UIEvent e = uiE as UIEvent;
             if (e == E)
             {
                 this.UIContent.Children.Remove(uiE);
                 UIEvents.Remove(E);
                 return;
             }
         }
     }
     foreach (UIElement uiE in this.UIContentScroll.Children)
     {
         if (uiE is UIEvent)
         {
             UIEvent e = uiE as UIEvent;
             if (e == E)
             {
                 this.UIContentScroll.Children.Remove(uiE);
                 UIEvents.Remove(E);
                 return;
             }
         }
     }
 }
 public void LoadUI()
 {
     this.Clear();
     GroupEvent.ExpansionIndex = new List<int>();
     if (this.Events == null)
         return;
     foreach (Event e in this.Events)
     {
         if (e.loop)
         {
             e.Begin = e.Begin.setDate(this.curDateView.Date);
             e.End = e.End.setDate(this.curDateView.Date);
         }
         if (e.End.Date >= this.curDateView.Date && e.Begin.Date <= this.curDateView.Date)
         {
             for (int i = e.beginIndex(this.curDateView); i <= e.EndIndex(this.curDateView); i++)
             {
                 UITime time = this.UICalendar.Children[i] as UITime;
                 if (time != null && time.hasEvent == false)
                 {
                     time.hasEvent = true;
                     GroupEvent.ExpansionIndex.Add(i);
                 }
             }
         }
     }
     this.UpdateLayout();
     for (int i = 0; i < this.Events.Count; i++)
     {
         Event e = this.Events[i];
         if (e.End.Date >= this.curDateView.Date && e.Begin.Date <= this.curDateView.Date)
         {
             UIEvent UIE = new UIEvent();
             if (e.isAllDay(this.curDateView))
             {
                 e.Width = this.UICalendar.Width - 110;
                 e.Height = 38;
                 e.Left = 0;
                 UIE.Event = e;
                 UIE.Orientation = Orientation.Horizontal;
                 UIE.DeleteEvent += UIE_DeleteEvent;
                 UIE.AddChildEvent += UIE_AddChildEvent;
                 UIE.EditEvent += UIE_EditEvent;
                 UIE.SelectEvent += UIE_SelectEvent;
                 UIE.LinkEvent+=UIE_LinkEvent;
                 this.Time_0.AddChild(UIE);
             }
             else
             {
                 int index = e.comitBeginIndex(this.curDateView);
                 e.Top = e.getTop(this.curDateView);
                 e.Height = e.getHeight(this.curDateView);
                 bool canAdd = false;
                 foreach (GroupEvent G in this.Groups)
                 {
                     if (G.Add(ref e))
                     {
                         UIE.Event = e;
                         canAdd = true;
                         break;
                     }
                 }
                 if(!canAdd)
                 {
                     GroupEvent gE = new GroupEvent(ModeGroup.Vertical, 20 + (this.Groups.Count * this.widthCol), this.widthCol - this.margin);
                     gE.Add(ref e);
                     this.Groups.Add(gE);
                     UIE.Event = e;
                     this.UICalendar.Width = this.Groups[this.Groups.Count - 1].Left + this.widthCol + 100;
                    
                 }
                 if (e.Height > 100)
                     UIE.Orientation = Orientation.Vertical;
                 else UIE.Orientation = Orientation.Horizontal;
                 UIE.DeleteEvent += UIE_DeleteEvent;
                 UIE.EditEvent += UIE_EditEvent;
                 UIE.AddChildEvent += UIE_AddChildEvent;
                 UIE.SelectEvent+=UIE_SelectEvent;
                 UIE.LinkEvent+=UIE_LinkEvent;
                 (this.UICalendar.Children[index] as UITime).AddChild(UIE);
             }
         }
     }
 }