//private void meetingDayList_MouseEnter(object sender, MouseEventArgs e) //{ // MeetingDayList item = (MeetingDayList)sender; // //foreach(MeetingDayList item in MeetingDaySP.Children.OfType<MeetingDayList>()) // //{ // // How to scroll the uiElement to the mouse position? // //var sv = (ScrollViewer)Template.FindName("PART_MyScrollViewer", this); // If you do not already have a reference to it somewhere. // //var ip = (ItemsPresenter)SV.Content; // var point = item.TranslatePoint(new Point() - (Vector)e.GetPosition(SV), ip); // SV.ScrollToVerticalOffset(point.Y + (item.ActualHeight / 2)); // //break; // //} //} private Dictionary <DateTime, List <UserMeeting> > GetUserMeetingDict_ByOrder(UserMeeting[] userMeetingAry, bool IsReverse) { Dictionary <DateTime, List <UserMeeting> > dict = new Dictionary <DateTime, List <UserMeeting> >(); if (IsReverse == true) { dict = userMeetingAry .OrderBy(item => DateTool.StringToDate(item.BeginTime)) .GroupBy(item => DateTool.StringToDate(item.BeginTime).Date) .Reverse() // 倒著排序,最新的在最上面 .ToDictionary(IGrouping => IGrouping.Key, IGrouping => IGrouping.ToList()); } else { dict = userMeetingAry .OrderBy(item => DateTool.StringToDate(item.BeginTime)) .GroupBy(item => DateTool.StringToDate(item.BeginTime).Date) //.Reverse() // 倒著排序,最新的在最上面 .ToDictionary(IGrouping => IGrouping.Key, IGrouping => IGrouping.ToList()); } return(dict); }
private void InitUI(UserMeeting[] userMeetingAry, DateTime date) { string CourseOrMeeting_String = PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String; txtNothing.Text = string.Format("本月無{0}", CourseOrMeeting_String); txtPinCodeHint.Text = string.Format("請輸入{0}識別碼", CourseOrMeeting_String); btnAddHint.Text = string.Format("加入{0}", CourseOrMeeting_String); btnAddHint.Visibility = Visibility.Visible; if (userMeetingAry.Length > 0) { txtNothing.Visibility = Visibility.Collapsed; } else { txtNothing.Visibility = Visibility.Visible; } MeetingListDate = date; txtCount.Text = string.Format("共 {0} 個{1}", userMeetingAry.Length.ToString(), CourseOrMeeting_String); txtDate.Text = date.ToString("yyyy年MM月"); if (PaperLess_Emeeting.Properties.Settings.Default.IsNewMeeting_PopupDialog == false) { txtPinCodeHint.Visibility = Visibility.Visible; txtPinCode.Visibility = Visibility.Visible; } Task.Factory.StartNew(() => { Dictionary <DateTime, List <UserMeeting> > dict = new Dictionary <DateTime, List <UserMeeting> >(); //dict = GetUserMeetingDict_ByOrder(userMeetingAry, PaperLess_Emeeting.Properties.Settings.Default.UserMeeting_Reverse); if (PaperLess_Emeeting.Properties.Settings.Default.UserMeeting_Reverse == true) { dict = userMeetingAry .OrderBy(item => DateTool.StringToDate(item.BeginTime)) .GroupBy(item => DateTool.StringToDate(item.BeginTime).Date) .Reverse() // 倒著排序,最新的在最上面 .ToDictionary(IGrouping => IGrouping.Key, IGrouping => IGrouping.ToList()); } else { dict = userMeetingAry .OrderBy(item => DateTool.StringToDate(item.BeginTime)) .GroupBy(item => DateTool.StringToDate(item.BeginTime).Date) //.Reverse() // 倒著排序,最新的在最上面 .ToDictionary(IGrouping => IGrouping.Key, IGrouping => IGrouping.ToList()); } //改成用DispatcherPriority,因為如果快速換月份 //一直跑UI,馬上又丟棄太浪費資源 //改成有空閒再跑會議日期就好 //不過後來想一想,會議日期先跑出來 //會有馬上就撈到資料的感覺,停頓感比較小,所以再改回去。 //this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action(() => this.Dispatcher.BeginInvoke(new Action(() => { try { MeetingDaySP.Children.Clear(); ////添加一些空白會議 //dict.Add(new DateTime(2001 ,1 ,1), new List<UserMeeting>()); //dict.Add(new DateTime(2002 ,1 ,1), new List<UserMeeting>()); //dict.Add(new DateTime(2003, 1, 1), new List<UserMeeting>()); //dict.Add(new DateTime(2004, 1, 1), new List<UserMeeting>()); //dict.Add(new DateTime(2005, 1, 1), new List<UserMeeting>()); //dict.Add(new DateTime(2006, 1, 1), new List<UserMeeting>()); //dict.Add(new DateTime(2007, 1, 1), new List<UserMeeting>()); //dict.Add(new DateTime(2008, 1, 1), new List<UserMeeting>()); //dict.Add(new DateTime(2009, 1, 1), new List<UserMeeting>()); if (PaperLess_Emeeting.Properties.Settings.Default.UserMeeting_Reverse == false) { foreach (KeyValuePair <DateTime, List <UserMeeting> > item in dict) { MeetingDayList meetingDayList = new MeetingDayList(UserID, UserPWD, item.Key, item.Value as List <UserMeeting>, this.Home_Change2MeetingDataCT_Event, new MeetingList_Show_HiddenMeetingDayList_Function(Show_HiddenMeetingDayList), NewAddMeetingID); MeetingDaySP.Children.Add(meetingDayList); } } else { bool HasToday = dict.Any(x => x.Key.Day == DateTime.Now.Day); int NearByTodayIndex = 0; if (MeetingListDate.Month == DateTime.Now.Month) { if (HasToday == true) { NearByTodayIndex = dict.ToList().FindIndex(x => x.Key.Day == DateTime.Now.Day); } else { //if (NearByTodayIndex > 0) // NearByTodayIndex--; Dictionary <DateTime, List <UserMeeting> > tempDict = new Dictionary <DateTime, List <UserMeeting> >(dict); tempDict.Add(DateTime.Now, new List <UserMeeting>()); NearByTodayIndex = tempDict.OrderBy((x) => x.Key.Day).ToList().FindIndex(x => x.Key.Day == DateTime.Now.Day); //if (NearByTodayIndex == dict.Count - 1) //{ // NearByTodayIndex--; //} } } MeetingDayList MeetingDayList_ToScroll = null; int i = 0; //Button btnShowMeetingRooms = null; foreach (KeyValuePair <DateTime, List <UserMeeting> > item in dict) { MeetingDayList meetingDayList = new MeetingDayList(UserID, UserPWD, item.Key, item.Value as List <UserMeeting>, this.Home_Change2MeetingDataCT_Event, new MeetingList_Show_HiddenMeetingDayList_Function(Show_HiddenMeetingDayList), NewAddMeetingID); MeetingDaySP.Children.Add(meetingDayList); if (i == NearByTodayIndex || NearByTodayIndex == dict.Count - 1 || int.Parse(meetingDayList.date.ToString("yyyyMMdd")) <= int.Parse(DateTime.Now.ToString("yyyyMMdd"))) { MeetingDayList_ToScroll = meetingDayList; } else if (MeetingDayList_ToScroll == null) { meetingDayList.Visibility = Visibility.Collapsed; if (btnShowMeetingRooms == null) { btnShowMeetingRooms = new Button() { Content = "^", Height = 0, //現在已經隱藏起來了,需要的話把高度調高 BorderThickness = new Thickness(0), Background = new SolidColorBrush(Colors.Yellow) }; btnShowMeetingRooms.Margin = new Thickness(12, 0, 12, 0); btnShowMeetingRooms.Click += (sender, e) => { //AutoClosingMessageBox.Show("xxx"); btnShowMeetingRooms.Visibility = Visibility.Collapsed; Show_HiddenMeetingDayList(); }; btnShowMeetingRooms.MouseEnter += (sender, e) => { btnShowMeetingRooms.Visibility = Visibility.Collapsed; Show_HiddenMeetingDayList(); }; MeetingDaySP.Children.Add(btnShowMeetingRooms); } } i++; } //double height = System.Windows.SystemParameters.PrimaryScreenHeight; Rectangle rect = new Rectangle(); rect.Height = 1080; //rect.Height = height - MeetingDaySP.Children.Count * 125; rect.Margin = new Thickness(12, 0, 12, 0); rect.Fill = new SolidColorBrush(Colors.Transparent); MeetingDaySP.Children.Add(rect); } } catch (Exception ex) { LogTool.Debug(ex); } })); }); }