123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857 |
- using HistoryDLL.Json;
- using MediaViewerLib.Utilities;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Threading;
- namespace HistoryDLL
- {
- /// <summary>
- /// CyclicScroller.xaml 的互動邏輯
- /// </summary>
- public partial class CyclicScroller : UserControl
- {
- public enum HistoryControlMode
- {
- Boot = 0x001,
- Manual = 0x010,
- AutoRun = 0x100,
- };
- public enum TouchorManipulation
- {
- TouchEvent = 0x01,
- ManipulationEvent = 0x10,
- };
- public enum MonitorFlag
- {
- Monitor1_1 = 0x000001,
- Monitor2_1 = 0x000010,
- Monitor3_1 = 0x000100,
- Monitor4_1 = 0x001000,
- Monitor5_1 = 0x010000,
- Monitor6_1 = 0x100000,
- };
- public enum StoryBoardStatus
- {
- StoryBoardIsRun = 0x01,
- StoryBoardIsStop = 0x10,
- };
- public delegate void HomeBackInforDelegate();
- public event HomeBackInforDelegate HomeBackInforEvent;
- public event EventHandler OnDataLoadCompeleted;
- //創造 LiveContainer 物件的Delegate
- private delegate void CreateLiveContainerDelegate();
- //從xml 中取得時際實際有多少個年份資料
- private List<XmlData> xmlDataList = new List<XmlData>();
- //透過取得的年份將MainEvent建立出來後放到該Buffer中
- private List<LiveContainer> LiveContainerList = new List<LiveContainer>();
- //Get Windows Resolution (根據 n * 1的螢幕取得windows的寬高)
- private static WindowsResolution CurrentMonitorCount = new WindowsResolution();
- //public static ConfigSettingClass config = new ConfigSettingClass(GlobalFunction.ConfigSettingFilePath, CurrentMonitorCount);
- //當前載入的起始位置 0 : 代表當前第一個年份是xml資料的首年
- private int currentLoadIndex = 0;
- //是否需要"當前"年份顯示在正中間
- private bool NeedToGetCenter = true;
- private int CenterIndexValue = 0;
- //是否要有首頁動畫
- private bool RunHomePageAnimation = true;
- //TouchDown 事件是否有發生 ?
- private bool isTouchDown = false;
- private bool isManipulatonEvent = false;
- private bool isAutoRun = false;
- //移動前 Horizontal.X的值
- double MoveStartHorizontalX = 0.0;
- //移動後 Horizontal.X的值
- double MoveEndHorizontalX = 0.0;
- //從開始到結束全部的移動距離
- double MoveTotalDistance = 0.0;
- //容許開始到結束的全部移動量小於該值則為點擊事件
- double AllowMaxDistance = 8000;
- //重新定位的Storyboard
- private Storyboard storyboardForLocate = new Storyboard();
- private StoryBoardStatus storyboardStatus = StoryBoardStatus.StoryBoardIsStop;
- //重新定位的 Storyboard 速度調整係數
- private int StorySmoothValue = 300;
- //輪播的Storyboard
- private Storyboard autoRunStoryboard = new Storyboard();
- //當前歷史牆載入完成
- private bool isHistoryWallLoadComplete = false;
- //狀態為手動或者輪播模式
- public HistoryControlMode ControlMode = HistoryControlMode.Boot;
- //Loading~
- HomePage hp;
- public CyclicScroller(int languageIndex)
- {
- InitializeComponent();
-
- if (ConfigSettingClass.MainBackCollect == null)
- {
- MessageBox.Show("設定錯誤,請透過後台更新設定!!");
- Application.Current.Shutdown();
- return;
- }
- //初始化除了Spec外的基本設定
- //refresh setting
- new ConfigSettingClass(GlobalFunction.ConfigSettingFilePath, CurrentMonitorCount);
- InitialWholeSetting();
- if (GlobalFunction.isSolutionUsing4K)
- {
- MainEventWidth *= 2;
- MainEventHeight *= 2;
- YearEventHeight *= 2;
- this.uxMyScroll.Margin = new Thickness(this.uxMyScroll.Margin.Left, this.uxMyScroll.Margin.Top, this.uxMyScroll.Margin.Right, this.uxMyScroll.Margin.Bottom * 2);
- }
- if (CurrentMonitorCount.ncm == 0)
- {
- MessageBox.Show("螢幕解析度取得失敗, 可能會造成載入異常!!");
- Application.Current.Shutdown();
- return;
- }
- this.Loaded += new RoutedEventHandler(CyclicScroller_Loaded);
- this.KeyDown += new KeyEventHandler(CyclicScroller_KeyDown);
- }
- private void CyclicScroller_KeyDown(object sender, KeyEventArgs e)
- {
- //取得Ctrl + s進入後台設定
- if (e.Key == Key.S && Keyboard.Modifiers == ModifierKeys.Shift)
- {
- Exception closeEx = CloseProcess("nLightenHistoryWallEdit");
- if (closeEx != null)
- {
- Debug.WriteLine(closeEx.Message);
- }
- Thread.Sleep(100);
- Exception ex = OpenProcess(AppDomain.CurrentDomain.BaseDirectory + "nLightenHistoryWallEdit.exe");
- if (ex != null)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- void CyclicScroller_Loaded(object sender, RoutedEventArgs e)
- {
- //取得資料
- if (!GetHistoryData())
- {
- MessageBox.Show("資料準備中,敬請期待!");
- Application.Current.Shutdown();
- return;
- }
- //*設定規範值請參閱 SpecificationValue.cs file.
- SetSpecValue();
- //設定當前語系
- SetLanguage();
- //設定回正被中斷時~應該回到的顯示位置
- SetReturnPos();
- //根據螢幕數量~顯示螢幕中會有幾個內容(children)
- ChildrenCount = GetChildrenCount();
- //根據可以顯示的 Children 數量~新建出 Grid For 裝載DetailViewer
- CreateExtraUnitGrid();
- //初始化該 ExtraUnitGrid ~包括 狀態 位置
- InitializeExtraUnitGrid();
- //拖動隱藏區塊顯示設定
- SetDisplayPart();
- //將首頁輪播 LoadBar 加到畫面中
- AddHomePageAnimation();
- //計算總事件~並將該直傳到Homepage中
- CalcCountToHomePage();
- //延遲載入~避免程式咬死
- WpfDelayDoWork.DoBackgroundWork(CreateLiveConainer, 1000);
- }
- private void CreateLiveConainer()
- {
- if (xmlDataList.Count <= 0)
- { return; }
- //Loading Start
- LoadingStart();
- //總共會有多少筆 MainEvent ? 透過 YearList 中的個數將 MainEvent 預先建立起來
- CreatMainEvent();
- //是否需要將首年顯示在中間
- if (NeedToGetCenter)
- {
- CenterIndexValue = GetCenterIndexValue();
- }
- //之後代表會有 ChildrenCount 個數量會在 Scrollviewer 當中
- currentLoadIndex = GetIndexFromLeftSide();
- currentLoadIndex -= CenterIndexValue;
- AddEventBlock(currentLoadIndex, false);
- //回正Storyboard
- BackToPosFromCurrentLoadIndex(currentLoadIndex);
- //自動輪播
- GlobalFunction.CheckAutoRunTimer.Start();
- isHistoryWallLoadComplete = true;
- }
- //回正
- private void BackToPosFromCurrentLoadIndex(int currentLoadIndex)
- {
- isTouchDown = false;
- double dd = Math.Abs(MainEventWidth + NoneUseRange - uxMyScroll.HorizontalOffset) / StorySmoothValue;
- if (dd <= 0.3)
- {
- dd = 0.3;
- }
- else if (dd >= 0.5)
- {
- dd = 0.5;
- }
- //完成後由 storyboard 回到中間位置
- DoubleAnimation dbOffset = new DoubleAnimation()
- {
- Duration = TimeSpan.FromSeconds(dd),
- EasingFunction = new PowerEase()
- {
- EasingMode = EasingMode.EaseOut,
- Power = 2
- },
- };
- ScrollViewerUtilities.UseMotionStop = false;
- Storyboard.SetTarget(dbOffset, (DependencyObject)this.FindName("uxMyScroll"));
- Storyboard.SetTargetProperty(dbOffset, new PropertyPath(ScrollViewerUtilities.HorizontalOffsetProperty));
- storyboardForLocate.Children.Add(dbOffset);
- storyboardForLocate.FillBehavior = FillBehavior.HoldEnd;
- dbOffset.From = uxMyScroll.HorizontalOffset;
- dbOffset.To = MainEventWidth + NoneUseRange;
- SetStoryBoardStatus(StoryBoardStatus.StoryBoardIsRun);
- }
- void storyboardForLocate_Completed(object sender, EventArgs e)
- {
- SetStoryBoardStatus(StoryBoardStatus.StoryBoardIsStop);
- if (ControlMode == HistoryControlMode.Boot)
- {
- ControlMode = HistoryControlMode.Manual;
- }
- //確實停止後才開始判斷是否為點擊sdlu
- if (storyboardStatus == StoryBoardStatus.StoryBoardIsStop)
- {
- if (MoveTotalDistance <= AllowMaxDistance)
- {
- //通知 判斷為點擊
- SendInfoToLiveContainer(TouchorManipulation.TouchEvent);
- }
- else
- {
- //通知 判斷為Manipulation
- SendInfoToLiveContainer(TouchorManipulation.ManipulationEvent);
- }
- MoveTotalDistance = 0.0;
- //改變被點擊開的兩旁資訊
- ChangeDetailSide();
- }
- }
- //啟動或停止回正的storyboard
- private void SetStoryBoardStatus(StoryBoardStatus sbs)
- {
- if (sbs == StoryBoardStatus.StoryBoardIsRun)
- {
- storyboardForLocate.Begin();
- storyboardStatus = sbs;
- }
- else if (sbs == StoryBoardStatus.StoryBoardIsStop)
- {
- storyboardForLocate.Stop();
- storyboardStatus = sbs;
- }
- }
- #region 將每個年份事件區塊加到 Scrollviewer 中
- /// <summary>
- /// 將要顯示的事件區塊加到 StackPanel 中
- /// </summary>
- /// <param name="startIndex">從事件包(LiveContainerList)中取出事件的起始索引位置</param>
- /// <param name="IsRightSide">往左邊改變或者往右邊改變</param>
- private void AddEventBlock(int startIndex, bool IsRightSide)
- {
- if (ClearScrollChildren(IsRightSide))
- {
- for (int index = 0; index < ChildrenCount + 2; index++)
- {
- int addcount = (startIndex + index) % LiveContainerList.Count;
- AddGridIntoScroll(addcount, index, true);
- }
- }
- else //如果不是第一次載入~代表該狀況為移動畫面造成改變~所以依照移動的方向做區塊的改變
- {
- int index = 0;
- //由右到左
- if (IsRightSide)
- {
- index = ChildrenCount + 1;
- }
- else //由左到右
- {
- index = 0;
- }
- int addcount = (startIndex + index) % LiveContainerList.Count;
- AddGridIntoScroll(addcount, index, IsRightSide);
- }
- //改變年份區塊的索引值與顏色
- ChangeBlockColor();
- //**改變視角位置 (移動到中間的區塊)**
- if (IsRightSide)
- {
- uxMyScroll.ScrollToHorizontalOffset(uxMyScroll.HorizontalOffset - MainEventWidth);
- }
- else
- {
- uxMyScroll.ScrollToHorizontalOffset(uxMyScroll.HorizontalOffset + MainEventWidth);
- }
- }
- private void ChangeBlockColor()
- {
- //更新物件在Scroller中的索引位置~並改變其顏色
- for (int count = 0; count < uxMyStackPanel.Children.Count; count++)
- {
- ((LiveContainer)uxMyStackPanel.Children[count]).Set_Get_ContainerIndex = count;
- if (count <= 1 || count >= ChildrenCount)
- {
- ((LiveContainer)uxMyStackPanel.Children[count]).ChangeControlColor(false);
- }
- else
- ((LiveContainer)uxMyStackPanel.Children[count]).ChangeControlColor(true);
- }
- }
- private bool ClearScrollChildren(bool IsRightSide)
- {
- //如果整個Panel都沒有物件的話代表這是第一次載入物件~所以不須執行任何移除物件的動作
- if (uxMyStackPanel.Children.Count > 0)
- {
- if (IsRightSide)
- {
- //移除第一個
- ((LiveContainer)uxMyStackPanel.Children[0]).Set_Get_ContainerIndex = -1;
- uxMyStackPanel.Children.RemoveAt(0);
- }
- else
- {
- //移除最後一個
- ((LiveContainer)uxMyStackPanel.Children[uxMyStackPanel.Children.Count - 1]).Set_Get_ContainerIndex = -1;
- uxMyStackPanel.Children.RemoveAt(uxMyStackPanel.Children.Count - 1);
- }
- return false;
- }
- return true;
- }
- /// <summary>
- /// 新增一個區塊到 Stackpanel 中
- /// </summary>
- /// <param name="addcount">要新增的區塊是事件包 (LiveContainerList)中的哪一個</param>
- /// <param name="index">主要是回報給Homepage, 是哪幾個年份區塊在stackpanel 中</param>
- /// <param name="IsAddBlock">新增的方式是 Add or Insert</param>
- private void AddGridIntoScroll(int addcount, int index, bool IsAddBlock)
- {
- if (IsAddBlock)
- {
- uxMyStackPanel.Children.Add(LiveContainerList[addcount]);
- }
- else
- {
- uxMyStackPanel.Children.Insert(0, LiveContainerList[addcount]);
- }
- //將初始完成後~顯示在畫面中的年份資料傳給Homepage
- if (RunHomePageAnimation)
- {
- if (index >= 1 && index <= ChildrenCount)
- {
- hp.xmlDataList.Add(LiveContainerList[addcount].xmlData);
- }
- }
- }
- #endregion
- /// <summary>
- /// 透過 YearList 中的個數將 MainEvent 預先建立起來"如不足則循環"
- /// </summary>
- private void CreatMainEvent()
- {
- //"如不足則循環"方式為~依照各螢幕數量不同給予不同的常數值
- int staticvalue = GetCycleCount();
- for (int index = 0; index < staticvalue; index++)
- {
- for (int count = 0; count < xmlDataList.Count; count++)
- {
- LiveContainer liveContainer = new LiveContainer(xmlDataList[count], MainEventWidth, MainEventHeight);
- //通知 LiveContainer 通道
- liveContainer.ListenFromCyclicTouchStatus(this);
- //接收來自 LiveContainer 通道
- liveContainer.LiveContainerBubbleToCyclicScrollerEvent += new LiveContainer.LiveContainerBubbleToCyclicScroller(ReceiveFromLiveContainerInfo);
- liveContainer.CreateLiveContainer();
- LiveContainerList.Add(liveContainer);
- }
- }
- }
- /// <summary>
- /// 這邊的計算方式為~
- /// 如果是單螢幕則全部需要ChildrenCount個加四個備份所以是ChildrenCount + 4個,
- /// 雙螢幕需要ChildrenCount個加四個備份所以是ChildrenCount + 4個,
- /// 三螢幕需要ChildrenCount個加四個備份所以是ChildrenCount + 4個
- /// 如果xml中的年份不足, 則必須進行循環. 此result則為循環次數
- /// </summary>
- /// <returns></returns>
- private int GetCycleCount()
- {
- int result = 0;
- //如果設定的年份少於全部需要的則必須
- switch (CurrentMonitorCount.ncm)
- {
- case MonitorFlag.Monitor1_1:
- case MonitorFlag.Monitor2_1:
- case MonitorFlag.Monitor3_1:
- case MonitorFlag.Monitor4_1:
- case MonitorFlag.Monitor5_1:
- case MonitorFlag.Monitor6_1:
- {
- result = (TotalShowChildren / xmlDataList.Count) + 1;
- break;
- }
- }
- return result;
- }
- public static T DeserializeFromJson<T>(string json)
- {
- T deserializedProduct = JsonConvert.DeserializeObject<T>(json);
- return deserializedProduct;
- }
- /// <summary>
- /// //取得 ini 中的資料
- /// </summary>
- /// <returns></returns>
- private bool GetHistoryData()
- {
- List<EventGroup> eventgroups = new List<EventGroup>();
- HistoryWallEventJson hweventJson = new HistoryWallEventJson();
- if (File.Exists(GlobalFunction.JsonFilePath))
- {
- string jsonResult;
- xmlDataList.Clear();
- using (StreamReader sr = new StreamReader(GlobalFunction.JsonFilePath))
- {
- jsonResult = sr.ReadToEnd();
- }
- hweventJson = DeserializeFromJson<HistoryWallEventJson>(jsonResult);
- eventgroups = hweventJson.EventGroups;
- if (hweventJson.EventGroups.Count <= 0)
- {
- return false;
- }
- for (int index = 0; index < hweventJson.EventGroups.Count; index++)
- {
- if (hweventJson.EventGroups[index].ListDates.Count > 0)
- {
- XmlData xmldata = new XmlData(hweventJson.EventGroups[index]);
- xmlDataList.Add(xmldata);
- }
- }
- }
- else
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 自動移動
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void AutoRunTimer_Tick(object sender, EventArgs e)
- {
- uxMyScroll.ScrollToHorizontalOffset(uxMyScroll.HorizontalOffset + 1);
- }
- private void uxMyScroll_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
- {
- if (isHistoryWallLoadComplete)
- {
- SetStoryBoardStatus(StoryBoardStatus.StoryBoardIsStop);
- isTouchDown = true;
- isManipulatonEvent = false;
- MoveStartHorizontalX = uxMyScroll.HorizontalOffset;
- }
- e.Handled = true;
- }
- private void uxMyScroll_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
- {
- if (isTouchDown)
- {
- uxMyScroll.ScrollToHorizontalOffset(uxMyScroll.HorizontalOffset - e.DeltaManipulation.Translation.X);
- MoveTotalDistance += Math.Abs(uxMyScroll.HorizontalOffset - e.DeltaManipulation.Translation.X);
- }
- e.Handled = true;
- }
- private void uxMyScroll_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
- {
- if (isTouchDown)
- {
- isTouchDown = false;
- BackToPosFromCurrentLoadIndex(currentLoadIndex);
- }
- isManipulatonEvent = false;
- e.Handled = true;
- }
- private void uxMyScroll_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingEventArgs e)
- {
- e.TranslationBehavior = new InertiaTranslationBehavior()
- {
- InitialVelocity = e.InitialVelocities.LinearVelocity,
- DesiredDeceleration = 20.0 * 96.0 / (1000.0 * 1000.0)
- };
- e.Handled = true;
- }
- /// <summary>
- /// 改變被點擊開的兩旁資訊
- /// </summary>
- private void ChangeDetailSide()
- {
- int count = ExtraUnitGridList.Count;
- for (int index = 0; index < count; index++)
- {
- if (ExtraUnitGridList[index].IsUsing != 0 &&
- ExtraUnitGridList[index].Get_Set_BlockControlMode != ExtraUnitGrid.ControlMode.Extend)
- {
- int mappingStackpanel = index + 1;
- if (((LiveContainer)uxMyStackPanel.Children[mappingStackpanel]).uxYearStr.Text != ExtraUnitGridList[index].textblock.Text)
- {
- if (ExtraUnitGridList[index].Get_Set_BlockControlMode != ExtraUnitGrid.ControlMode.MinStatus)
- {
- ExtraUnitGridList[index].textblock.Text = ((LiveContainer)uxMyStackPanel.Children[mappingStackpanel]).uxYearStr.Text;
- }
- ThumbnailContainer thumbnailControl = new ThumbnailContainer();
- List<string> folderPaths = new List<string>();
- ExtraUnitGridList[index].DetailViewerControlHide();
- folderPaths = GetThumbnailControl(mappingStackpanel);
- thumbnailControl.ImgPath = MediaUtilties.GetImageFromFolders(folderPaths.ToArray());
- ExtraUnitGridList[index].BorderUp.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
- ExtraUnitGridList[index].BorderUp.Child = thumbnailControl;
- ExtraUnitGridList[index].DetailViewerControlShow(null, null);
- }
- }
- }
- }
- private Exception OpenProcess(string exePath)
- {
- if (File.Exists(exePath))
- {
- ProcessStartInfo startInfo = new ProcessStartInfo();
- startInfo.FileName = exePath;
- try
- {
- Process startProcess = Process.Start(startInfo);
- return null;
- }
- catch (Exception ex)
- {
- return ex;
- }
- }
- else
- {
- return new Exception(exePath + "檔案不存在!");
- }
- }
- private Exception CloseProcess(string processName)
- {
- try
- {
- bool isKill = false;
- System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
- foreach (System.Diagnostics.Process myProcess in myProcesses)
- {
- if (myProcess.ProcessName == processName)
- {
- Debug.WriteLine(myProcess.ProcessName + " " + myProcess.MainWindowHandle.ToString());
- myProcess.Kill();
- isKill = true;
- }
- }
- if (isKill)
- {
- return null;
- }
- else
- {
- return new Exception("Cannot find " + processName);
- }
- }
- catch (Exception ex)
- {
- return ex;
- }
- }
- private void Window_PreviewTouchDown(object sender, TouchEventArgs e)
- {
- //停止輪播
- StopAutoRunTheWall();
- GlobalFunction.CheckAutoRunTimer.Stop();
- }
- //避免點擊在非歷史軸的時, 歷史軸會因為輪播停止而卡住的狀況
- private void Window_PreviewTouchUp(object sender, TouchEventArgs e)
- {
- if (!isManipulatonEvent && isHistoryWallLoadComplete && isAutoRun)
- {
- BackToPosFromCurrentLoadIndex(currentLoadIndex);
- }
- isAutoRun = false;
- if (!GlobalFunction.isVideoPlay)
- GlobalFunction.CheckAutoRunTimer.Start();
- }
- private void uxMyScroll_ScrollChanged(object sender, System.Windows.Controls.ScrollChangedEventArgs e)
- {
- if (ControlMode == HistoryControlMode.Boot)
- {
- return;
- }
- MoveEndHorizontalX = uxMyScroll.HorizontalOffset;
- //手指頭往左邊的移動
- if (MoveEndHorizontalX > MainEventWidth * 2 + NoneUseRange - (MainEventWidth / 2))
- {
- autoRunStoryboard.Stop();
- //判斷當前的Index是否超出"最大"容許範圍~進行調整
- currentLoadIndex = GetIndexFromRightSide();
- //重新加入EventBlock
- AddEventBlock(currentLoadIndex, true);
- if (ControlMode == HistoryControlMode.AutoRun)
- {
- SetAutoRunStoryBoard(MoveEndHorizontalX - MainEventWidth, MoveEndHorizontalX - MainEventWidth + MainEventWidth);
- autoRunStoryboard.Begin();
- }
- }
- //手指頭往右邊的移動
- else if (MoveEndHorizontalX < MainEventWidth + NoneUseRange - (MainEventWidth / 2))
- {
- //判斷當前的Index是否低於"最小"容許範圍~進行調整
- currentLoadIndex = GetIndexFromLeftSide();
- //重新加入EventBlock
- AddEventBlock(currentLoadIndex, false);
- }
- }
- #region 切換語系與回首頁按鈕
- private void ChangeLangBtn_Click(object sender, RoutedEventArgs e)
- {
- int changeLanIndex = 0;
- if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 0)
- {
- if (canUsingLangList[1])
- {
- changeLanIndex = 1;
- }
- else if (canUsingLangList[2])
- {
- changeLanIndex = 2;
- }
- else if (canUsingLangList[3])
- {
- changeLanIndex = 3;
- }
- }
- else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 1)
- {
- if (canUsingLangList[2])
- {
- changeLanIndex = 2;
- }
- else if (canUsingLangList[3])
- {
- changeLanIndex = 3;
- }
- else if (canUsingLangList[0])
- {
- changeLanIndex = 0;
- }
- }
- else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 2)
- {
- if (canUsingLangList[3])
- {
- changeLanIndex = 3;
- }
- else if (canUsingLangList[0])
- {
- changeLanIndex = 0;
- }
- else if (canUsingLangList[1])
- {
- changeLanIndex = 1;
- }
- }
- else if (ConfigSettingClass.MainBackCollect.DefaultLangIndex == 3)
- {
- if (canUsingLangList[0])
- {
- changeLanIndex = 0;
- }
- else if (canUsingLangList[1])
- {
- changeLanIndex = 1;
- }
- else if (canUsingLangList[2])
- {
- changeLanIndex = 2;
- }
- }
- if (changeLanIndex == 0)
- {
- ConfigSettingClass.MainBackCollect.DefaultLangIndex = changeLanIndex;
- System.Windows.Application.Current.Properties["Language"] = "Language1";
- }
- else if (changeLanIndex == 1)
- {
- ConfigSettingClass.MainBackCollect.DefaultLangIndex = changeLanIndex;
- System.Windows.Application.Current.Properties["Language"] = "Language2";
- }
- else if (changeLanIndex == 2)
- {
- ConfigSettingClass.MainBackCollect.DefaultLangIndex = changeLanIndex;
- System.Windows.Application.Current.Properties["Language"] = "Language3";
- }
- else if (changeLanIndex == 3)
- {
- ConfigSettingClass.MainBackCollect.DefaultLangIndex = changeLanIndex;
- System.Windows.Application.Current.Properties["Language"] = "Language0";
- }
- uxMainLangBtnL.Content = ConfigSettingClass.MainBackCollect.LangText[ConfigSettingClass.MainBackCollect.DefaultLangIndex];
- uxMainLangBtnR.Content = ConfigSettingClass.MainBackCollect.LangText[ConfigSettingClass.MainBackCollect.DefaultLangIndex];
- for (int i = 0; i < LiveContainerList.Count; i++)
- {
- LiveContainerList[i].WriteYearBarStr();
- //改變事件區塊中顯示文字分兩部分
- //1. 已經在事件區塊中顯示的 Planerotate
- LiveContainerList[i].ChangeCurPlaneRotateLan();
- //2. 在緩衝區中待顯示的 Planerotate
- //LiveContainerList[i].ChangePlaneRotateLan();
- }
- for (int j = 0; j < ExtraUnitGridList.Count; j++)
- {
- if (ExtraUnitGridList[j].curDataIndex != -1)
- {
- ExtraUnitGridList[j].textblock.Text = ((LiveContainer)uxMyStackPanel.Children[j + 1]).uxYearStr.Text;
- }
- }
- }
- private void HomeBtn_Click(object sender, RoutedEventArgs e)
- {
- if (HomeBackInforEvent != null)
- this.Dispatcher.BeginInvoke(HomeBackInforEvent, DispatcherPriority.Background);
- }
- #endregion
- }
- public class WpfDelayDoWork
- {
- public static void DoWork(Action action, int millisecond = 300)
- {
- new Action<Dispatcher, Action, int>(DoWorkAsync).BeginInvoke(Dispatcher.CurrentDispatcher, action, millisecond, null, null);
- }
- public static void DoBackgroundWork(Action action, int millisecond = 300)
- {
- new Action<Dispatcher, Action, int>(DoBackgroundWorkAsync).BeginInvoke(Dispatcher.CurrentDispatcher, action, millisecond, null, null);
- }
- static void DoWorkAsync(Dispatcher dispatcher, Action action, int millisecond)
- {
- System.Threading.Thread.Sleep(millisecond);
- dispatcher.BeginInvoke(action);
- }
- static void DoBackgroundWorkAsync(Dispatcher dispatcher, Action action, int millisecond)
- {
- System.Threading.Thread.Sleep(millisecond);
- dispatcher.Invoke(action, DispatcherPriority.Background);
- }
- }
- }
|