private void RootView_Loaded(object sender, RoutedEventArgs e)
 {
     this.UICalendar.Width = this.Width;
     this.widthCol = (this.UICalendar.Width - 40) / this._numCol;
     this.Groups = new List<GroupEvent>();
     for (int i = 0; i < this._numCol; i++)
     {
         GroupEvent gE = new GroupEvent(ModeGroup.Vertical, 20 + (i * this.widthCol), this.widthCol - this.margin);
         this.Groups.Add(gE);
     }
     this.UICalendar.Width = this.Groups[this._numCol-1].Left+this.widthCol+100;
     this.LoadUI();
 }
 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);
             }
         }
     }
 }