ExtraUnit.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Animation;
  10. namespace HistoryDLL
  11. {
  12. public partial class CyclicScroller : UserControl
  13. {
  14. private List<ExtraUnitGrid> ExtraUnitGridList = new List<ExtraUnitGrid>();
  15. }
  16. public class ExtraUnitGrid : Grid
  17. {
  18. //外掛 Delegate event for communicate with CyclicScroller (通知用)
  19. public delegate void ExtraUnitGridBubbleToCyclicScroller(string ProcessCode, int index);
  20. public event ExtraUnitGridBubbleToCyclicScroller ExtraUnitGridBubbleToCyclicScrollerEvent;
  21. //原始物件寬度
  22. private int OriginalObjectWidth = 0;
  23. //放大後原始寬度必須增加的值
  24. private int ExtendValue = 400;
  25. //縮小一次的值
  26. public int ShrinkValueOne = 200;
  27. //展開縮小棟話時間
  28. private int MyStoryBoardTimeL = 200;
  29. private int MyStoryBoardTimeS = 100;
  30. //Storyboard delay time
  31. private int delayTime = 100;
  32. //紀錄方向
  33. private string Direction = "";
  34. private double detailviewerPos = -36;
  35. private double thumbnailPos = -7;
  36. //當前物件可被控制的狀態
  37. public enum ControlMode
  38. {
  39. //可展開 (正常狀態)
  40. CanExtend = 0x00001,
  41. //已經展開
  42. Extend = 0x00010,
  43. //不可展開 (處在最兩邊的無用地帶)
  44. UnUse = 0x00100,
  45. //縮小一次
  46. Clip = 0x01000,
  47. //縮小第二次 (最小寬度)
  48. MinStatus = 0x00000
  49. };
  50. public enum ObjectSize
  51. {
  52. OriginalSize = 0x0001,
  53. ShrinkNoneMarginSize = 0x0010,
  54. ShrinkMarginSize = 0x0100,
  55. ShrinkWholeSize = 0x1000
  56. }
  57. private int MonitorIndex;
  58. private ControlMode BlockControlMode;
  59. private ControlMode RecodeOriMode;
  60. public Border BorderUp = new Border();
  61. public Border BorderDown = new Border();
  62. //是否已經被加到畫面中
  63. public int IsUsing = 0;
  64. public TextBlock textblock = new TextBlock();
  65. public int curDataIndex = -1;
  66. //紀錄回到原位置的Margin值 ~以確保可以正確回到該位置
  67. public double RecodeMarginLeft = 0;
  68. private double borderupheight = 0;
  69. private double borderdownheight = 0;
  70. private double NonoUseSize = 0;
  71. private ObjectSize objSize = ObjectSize.OriginalSize;
  72. private double ThisMarginLeft = 0.0;
  73. public bool ExtendStoryboardRun = false;
  74. public bool ShrinkStoryboardRun = false;
  75. //下方方塊顏色
  76. private SolidColorBrush borderDownColor = new SolidColorBrush(ConfigSettingClass.TimelineExtentCollect.BackgroundColor);
  77. private SolidColorBrush TextBlockExtendColor = new SolidColorBrush(ConfigSettingClass.TimelineExtentCollect.TextColor);
  78. private SolidColorBrush TextBlockShrinkColor = new SolidColorBrush(ConfigSettingClass.TimelineCollect.TextColor);
  79. public int Get_Set_MonitorIndex
  80. {
  81. get { return MonitorIndex; }
  82. set
  83. {
  84. MonitorIndex = value;
  85. if (MonitorIndex >= 2)
  86. {
  87. ThisMarginLeft = (MonitorIndex - 2) * OriginalObjectWidth + (OriginalObjectWidth - NonoUseSize);
  88. }
  89. else
  90. {
  91. ThisMarginLeft = -NonoUseSize;
  92. }
  93. }
  94. }
  95. public ControlMode Get_Set_BlockControlMode
  96. {
  97. get { return BlockControlMode; }
  98. set { BlockControlMode = value; }
  99. }
  100. public ExtraUnitGrid(int Width, int Height, int DownHeight, int NoneUse)
  101. {
  102. int borderMargin = 5;
  103. if (GlobalFunction.isSolutionUsing4K)
  104. {
  105. ExtendValue *= 2;
  106. ShrinkValueOne *= 2;
  107. borderMargin *= 2;
  108. }
  109. this.Width = this.OriginalObjectWidth = Width;
  110. this.Height = Height + DownHeight;
  111. this.NonoUseSize = NoneUse;
  112. CutTheGrid();
  113. borderupheight = Height;
  114. borderdownheight = DownHeight;
  115. this.BorderUp.Height = Height;
  116. this.BorderUp.Height = 0;
  117. //this.BorderUp.Background = Brushes.Red;
  118. this.BorderUp.BorderBrush = Brushes.Transparent;
  119. this.BorderUp.BorderThickness = new Thickness(borderMargin);
  120. this.BorderDown.Height = DownHeight;
  121. this.BorderDown.Background = borderDownColor;
  122. //this.BorderDown.Background = Brushes.Green;
  123. this.BorderDown.BorderBrush = Brushes.Transparent;
  124. this.BorderDown.BorderThickness = new Thickness(borderMargin, borderMargin, borderMargin, GlobalFunction.isSolutionUsing4K ? 0 : borderMargin);
  125. //字體設定
  126. textblock.FontSize = GlobalFunction.isSolutionUsing4K ? 40 * 1.5 : 40;
  127. textblock.TextTrimming = TextTrimming.CharacterEllipsis;
  128. textblock.VerticalAlignment = System.Windows.VerticalAlignment.Center;
  129. textblock.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
  130. BorderDown.Child = textblock;
  131. this.Children.Add(BorderUp);
  132. this.Children.Add(BorderDown);
  133. Grid.SetRow(BorderUp, 0);
  134. Grid.SetRow(BorderDown, 1);
  135. this.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  136. this.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
  137. Get_Set_MonitorIndex = 0;
  138. IsUsing = 0;
  139. this.BorderDown.TouchUp += new EventHandler<System.Windows.Input.TouchEventArgs>(BorderDown_TouchUp);
  140. }
  141. public void SetOriControlMode(ControlMode Set)
  142. {
  143. RecodeOriMode = Set;
  144. }
  145. public void BorderDown_TouchUp(object sender, System.Windows.Input.TouchEventArgs e)
  146. {
  147. if (ExtendStoryboardRun)
  148. return;
  149. if (this.BlockControlMode == ControlMode.Extend)
  150. {
  151. this.Dispatcher.BeginInvoke(ExtraUnitGridBubbleToCyclicScrollerEvent, "Change", Get_Set_MonitorIndex);
  152. }
  153. }
  154. //回復原始大小動畫完成
  155. void Mystoryboard_Completed(object sender, EventArgs e)
  156. {
  157. this.Dispatcher.BeginInvoke(ExtraUnitGridBubbleToCyclicScrollerEvent, "Remove", Get_Set_MonitorIndex - 1);
  158. }
  159. private void CutTheGrid()
  160. {
  161. //切成上下兩塊
  162. RowDefinition rowDefinitionUp = new RowDefinition();
  163. RowDefinition rowDefinitionDown = new RowDefinition();
  164. rowDefinitionUp.Height = new GridLength(6, GridUnitType.Star);
  165. rowDefinitionDown.Height = new GridLength(1, GridUnitType.Star);
  166. //rowDefinitionDown.Height = new GridLength(GlobalFunction.isSolutionUsing4K ? 184 : 92, GridUnitType.Pixel);
  167. this.RowDefinitions.Add(rowDefinitionUp);
  168. this.RowDefinitions.Add(rowDefinitionDown);
  169. }
  170. #region 展開動畫 :
  171. /// <summary>
  172. /// 1.下方區塊先展開(0.2)
  173. /// 2.上方區塊由下往上升起(0.2)
  174. /// 3.call Detailviewer opacity changed(0.1)
  175. /// </summary>
  176. public void ExtendFunction()
  177. {
  178. this.BlockControlMode = ControlMode.Extend;
  179. this.textblock.Foreground = TextBlockExtendColor;
  180. //下方區塊的變化
  181. Storyboard Mystoryboard = new Storyboard();
  182. this.textblock.Opacity = 1;
  183. this.BorderUp.Opacity = 1;
  184. ExtendStoryboardRun = true;
  185. Mystoryboard = SetExtendChangeAnimation(MyStoryBoardTimeL, OriginalObjectWidth + ExtendValue);
  186. Mystoryboard.Completed += new EventHandler(EventContainerExtend_Complete);
  187. Mystoryboard.Begin();
  188. }
  189. //中間放大
  190. private Storyboard SetExtendChangeAnimation(int time, int ToValue)
  191. {
  192. Storyboard ResultStoryboard = new Storyboard();
  193. DoubleAnimation dbOffset = new DoubleAnimation()
  194. {
  195. Duration = TimeSpan.FromMilliseconds(time),
  196. EasingFunction = new CircleEase()
  197. {
  198. EasingMode = EasingMode.EaseOut,
  199. },
  200. From = this.Width,
  201. To = ToValue
  202. };
  203. ThicknessAnimation dbMargin = new ThicknessAnimation()
  204. {
  205. Duration = TimeSpan.FromMilliseconds(time),
  206. EasingFunction = new CircleEase()
  207. {
  208. EasingMode = EasingMode.EaseOut,
  209. },
  210. From = this.Margin,
  211. To = new Thickness(this.Margin.Left - Math.Abs(this.Width - ToValue) / 2, 0, 0, this.Margin.Bottom)
  212. };
  213. this.RenderTransformOrigin = new Point(0.5, 0.5);
  214. Storyboard.SetTarget(dbOffset, (DependencyObject)this);
  215. Storyboard.SetTarget(dbMargin, (DependencyObject)this);
  216. Storyboard.SetTargetProperty(dbOffset, new PropertyPath(Grid.WidthProperty));
  217. Storyboard.SetTargetProperty(dbMargin, new PropertyPath(Grid.MarginProperty));
  218. ResultStoryboard.Children.Add(dbOffset);
  219. ResultStoryboard.Children.Add(dbMargin);
  220. ResultStoryboard.FillBehavior = FillBehavior.HoldEnd;
  221. return ResultStoryboard;
  222. }
  223. private void EventContainerExtend_Complete(object sender, EventArgs e)
  224. {
  225. //上方區塊的變化
  226. Storyboard MystoryboardUp = new Storyboard();
  227. MystoryboardUp = ObjectAnimationToShow(MyStoryBoardTimeL, this.BorderUp.Height, borderupheight, detailviewerPos);
  228. MystoryboardUp.Completed += new EventHandler(DetailViewerControlShow);
  229. MystoryboardUp.Begin();
  230. }
  231. //Object is fade in
  232. internal void DetailViewerControlShow(object sender, EventArgs e)
  233. {
  234. //call detailviewer to show
  235. Grid gd = new Grid();
  236. gd = this.BorderUp.Child as Grid;
  237. if (gd != null && gd.Children.Count > 0)
  238. {
  239. if (gd.Children[0].ToString() == GlobalFunction.projectname + ".DetailViewer")
  240. {
  241. //sdlu
  242. //((DetailViewer)gd.Children[0]).StartOpacityAnimation();
  243. }
  244. }
  245. else if (this.BorderUp.Child.ToString() == GlobalFunction.projectname + ".ThumbnailContainer")
  246. {
  247. ((ThumbnailContainer)this.BorderUp.Child).StartOpacityAnimation();
  248. }
  249. ExtendStoryboardRun = false;
  250. }
  251. //Object is fade out
  252. internal void DetailViewerControlHide()
  253. {
  254. //call detailviewer to show
  255. Grid gd = new Grid();
  256. gd = this.BorderUp.Child as Grid;
  257. if (gd != null)
  258. {
  259. if (gd.Children[0].ToString() == "nLightenHistoryWall.DetailViewer")
  260. {
  261. //sdlu
  262. //((DetailViewer)gd.Children[0]).StopOpacityAnimation();
  263. }
  264. }
  265. else if (this.BorderUp.Child.ToString() == "nLightenHistoryWall.ThumbnailContainer")
  266. {
  267. ((ThumbnailContainer)this.BorderUp.Child).StopOpacityAnimation();
  268. }
  269. }
  270. //上方物件由下往上飛入
  271. private Storyboard ObjectAnimationToShow(int time, double fromValue, double toValue, double marginvalue)
  272. {
  273. Storyboard ResultStoryboard = new Storyboard();
  274. DoubleAnimation dbOffset = new DoubleAnimation()
  275. {
  276. Duration = TimeSpan.FromMilliseconds(time),
  277. EasingFunction = new CircleEase()
  278. {
  279. EasingMode = EasingMode.EaseOut,
  280. },
  281. From = fromValue,
  282. To = toValue
  283. };
  284. ThicknessAnimation dbMargin = new ThicknessAnimation()
  285. {
  286. Duration = TimeSpan.FromMilliseconds(time),
  287. EasingFunction = new ExponentialEase()
  288. {
  289. EasingMode = EasingMode.EaseOut,
  290. },
  291. From = new Thickness(this.BorderDown.Margin.Left, 0, 0, -borderdownheight),
  292. To = new Thickness(this.BorderDown.Margin.Left, 0, 0, marginvalue)
  293. };
  294. Storyboard.SetTarget(dbOffset, this.BorderUp);
  295. Storyboard.SetTarget(dbMargin, this.BorderUp);
  296. Storyboard.SetTargetProperty(dbOffset, new PropertyPath(Grid.HeightProperty));
  297. Storyboard.SetTargetProperty(dbMargin, new PropertyPath(Grid.MarginProperty));
  298. ResultStoryboard.Children.Add(dbOffset);
  299. ResultStoryboard.Children.Add(dbMargin);
  300. ResultStoryboard.FillBehavior = FillBehavior.HoldEnd;
  301. return ResultStoryboard;
  302. }
  303. #endregion
  304. private void SetCurrentObjSizeShrink(string Direction)
  305. {
  306. if (objSize == ObjectSize.OriginalSize)
  307. {
  308. if (Direction == "Left")
  309. {
  310. objSize = ObjectSize.ShrinkNoneMarginSize;
  311. }
  312. else if (Direction == "Right")
  313. {
  314. objSize = ObjectSize.ShrinkMarginSize;
  315. }
  316. }
  317. else if (objSize == ObjectSize.ShrinkNoneMarginSize)
  318. {
  319. if (Direction == "Right")
  320. {
  321. objSize = ObjectSize.ShrinkWholeSize;
  322. }
  323. }
  324. else if (objSize == ObjectSize.ShrinkMarginSize)
  325. {
  326. if (Direction == "Left")
  327. {
  328. objSize = ObjectSize.ShrinkWholeSize;
  329. }
  330. }
  331. else
  332. {
  333. objSize = ObjectSize.OriginalSize;
  334. }
  335. }
  336. private void SetCurrentObjSizeExtend(string Driection)
  337. {
  338. if (objSize == ObjectSize.ShrinkWholeSize)
  339. {
  340. if (Direction == "Left")
  341. {
  342. objSize = ObjectSize.ShrinkMarginSize;
  343. }
  344. else if (Direction == "Right")
  345. {
  346. objSize = ObjectSize.ShrinkNoneMarginSize;
  347. }
  348. }
  349. else if (objSize == ObjectSize.ShrinkNoneMarginSize || objSize == ObjectSize.ShrinkMarginSize)
  350. {
  351. objSize = ObjectSize.OriginalSize;
  352. }
  353. }
  354. private void GetTargetSizeAndPos(ObjectSize objectsize, ref double size, ref double pos)
  355. {
  356. int oriSize = 460;
  357. int shrSize = 260;
  358. int shrWholeSize = 60;
  359. int marginValue = 200;
  360. if (GlobalFunction.isSolutionUsing4K)
  361. {
  362. oriSize *= 2;
  363. shrSize *= 2;
  364. shrWholeSize *= 2;
  365. marginValue *= 2;
  366. }
  367. if (objectsize == ObjectSize.OriginalSize)
  368. {
  369. size = oriSize;
  370. pos = ThisMarginLeft;
  371. }
  372. else if (objectsize == ObjectSize.ShrinkNoneMarginSize)
  373. {
  374. size = shrSize;
  375. pos = ThisMarginLeft;
  376. }
  377. else if (objectsize == ObjectSize.ShrinkMarginSize)
  378. {
  379. size = shrSize;
  380. pos = ThisMarginLeft + marginValue;
  381. }
  382. else if (objectsize == ObjectSize.ShrinkWholeSize)
  383. {
  384. size = shrWholeSize;
  385. pos = ThisMarginLeft + marginValue;
  386. }
  387. }
  388. #region 兩旁縮小動畫
  389. /// <summary>
  390. /// 1.下方區塊先縮小(0.2)
  391. /// 2.上方區塊由下往上升起(0.1)
  392. /// 3.如果今天是縮小一次的狀態則call Detailviewer to changed opacity(0.1)
  393. /// </summary>
  394. /// <param name="Direction">相對於被點擊物件的位置方向</param>
  395. public void ShrinkFunction(string Direction)
  396. {
  397. Storyboard Mystoryboard = new Storyboard();
  398. this.textblock.Foreground = TextBlockShrinkColor;
  399. SetCurrentObjSizeShrink(Direction);
  400. if (this.BlockControlMode != ControlMode.Clip)
  401. {
  402. this.BlockControlMode = ControlMode.Clip;
  403. //縮第一次
  404. Mystoryboard = SetShrinkChangeAnimation(MyStoryBoardTimeL, objSize, Direction);
  405. Mystoryboard.Completed += new EventHandler(EventContainerShrink_Complete);
  406. this.textblock.Opacity = 1;
  407. this.BorderUp.Opacity = 1;
  408. Mystoryboard.Begin();
  409. }
  410. else if (this.BlockControlMode == ControlMode.Clip)
  411. {
  412. //縮第二次
  413. this.BlockControlMode = ControlMode.MinStatus;
  414. Mystoryboard = SetShrinkChangeAnimation(MyStoryBoardTimeS, objSize, Direction);
  415. this.textblock.Opacity = 0;
  416. this.BorderUp.Opacity = 0;
  417. Mystoryboard.Begin();
  418. }
  419. }
  420. private void EventContainerShrink_Complete(object sender, EventArgs e)
  421. {
  422. Storyboard MystoryboardUp = new Storyboard();
  423. MystoryboardUp = ObjectAnimationToShow(MyStoryBoardTimeL, this.BorderUp.Height, borderupheight, thumbnailPos);
  424. MystoryboardUp.Completed += new EventHandler(DetailViewerControlShow);
  425. MystoryboardUp.Begin();
  426. }
  427. private Storyboard SetShrinkChangeAnimation(int time, ObjectSize objectsize, string Direction)
  428. {
  429. Storyboard ResultStoryboard = new Storyboard();
  430. double size = 0;
  431. double pos = 0;
  432. GetTargetSizeAndPos(objectsize, ref size, ref pos);
  433. DoubleAnimation dbOffset = new DoubleAnimation()
  434. {
  435. Duration = TimeSpan.FromMilliseconds(time),
  436. EasingFunction = new ExponentialEase()
  437. {
  438. EasingMode = EasingMode.EaseIn,
  439. Exponent = 0.3
  440. },
  441. From = this.Width,
  442. To = size
  443. };
  444. ThicknessAnimation dbMargin = new ThicknessAnimation()
  445. {
  446. Duration = TimeSpan.FromMilliseconds(time),
  447. EasingFunction = new ExponentialEase()
  448. {
  449. EasingMode = EasingMode.EaseIn,
  450. Exponent = 0.3
  451. },
  452. From = this.Margin,
  453. To = new Thickness(pos, 0, 0, this.Margin.Bottom)
  454. };
  455. this.RenderTransformOrigin = new Point(0.5, 0.5);
  456. Storyboard.SetTarget(dbOffset, (DependencyObject)this);
  457. Storyboard.SetTargetProperty(dbOffset, new PropertyPath(Grid.WidthProperty));
  458. ResultStoryboard.Children.Add(dbOffset);
  459. Storyboard.SetTarget(dbMargin, (DependencyObject)this);
  460. Storyboard.SetTargetProperty(dbMargin, new PropertyPath(Grid.MarginProperty));
  461. ResultStoryboard.Children.Add(dbMargin);
  462. ResultStoryboard.FillBehavior = FillBehavior.HoldEnd;
  463. return ResultStoryboard;
  464. }
  465. #endregion
  466. private void EventContainerShrinkOneTime_Complete(object sender, EventArgs e)
  467. {
  468. this.textblock.Opacity = 1;
  469. this.BorderUp.Opacity = 1;
  470. DetailViewerControlShow(sender, e);
  471. }
  472. #region 回原始大小動畫
  473. public void ReturnToOriginalSize()
  474. {
  475. this.BlockControlMode = this.RecodeOriMode;
  476. //上方區塊變化
  477. Storyboard Mystoryboard = new Storyboard();
  478. this.IsUsing--;
  479. SetCurrentObjSizeShrink("");
  480. Mystoryboard = ObjectAnimationToHide(MyStoryBoardTimeL, this.BorderUp.Height, 0);
  481. Mystoryboard.Completed += new EventHandler(ReturnToOriginal_Complete);
  482. Mystoryboard.Begin();
  483. }
  484. private void ClearBorderUpChild()
  485. {
  486. Grid gd = BorderUp.Child as Grid;
  487. if (gd != null)
  488. {
  489. gd.Children.Clear();
  490. }
  491. }
  492. private void ReturnToOriginal_Complete(object sender, EventArgs e)
  493. {
  494. Storyboard Mystoryboard = new Storyboard();
  495. ClearBorderUpChild();
  496. Mystoryboard = SetOriginalChangeAnimation(MyStoryBoardTimeL, OriginalObjectWidth);
  497. Mystoryboard.Completed += new EventHandler(Mystoryboard_Completed);
  498. Mystoryboard.Begin();
  499. }
  500. #endregion
  501. #region 返回上一級大小
  502. /// <summary>
  503. /// 1.call Detailviewer to change opacity (0.1)
  504. /// 2.上方區塊由上往下縮到消失~
  505. /// 3.時間軸縮回(0.1)
  506. /// </summary>
  507. /// <param name="Direction"></param>
  508. public void BackSize(string Direction)
  509. {
  510. Storyboard Mystoryboard = new Storyboard();
  511. this.Direction = Direction;
  512. SetCurrentObjSizeExtend(Direction);
  513. DetailViewerControlHide();
  514. if (this.BlockControlMode == ControlMode.MinStatus)
  515. {
  516. this.IsUsing--;
  517. //縮回第一次
  518. this.BlockControlMode = ControlMode.Clip;
  519. Mystoryboard = SetBackSizeChangeAnimation(MyStoryBoardTimeL, objSize, Direction, 420);
  520. Mystoryboard.Completed += new EventHandler(EventContainerShrinkOneTime_Complete);
  521. Mystoryboard.Begin();
  522. }
  523. else if (this.BlockControlMode == ControlMode.Clip)
  524. {
  525. this.IsUsing--;
  526. //縮回原始大小
  527. this.BlockControlMode = this.RecodeOriMode;
  528. ClearBorderUpChild();
  529. Mystoryboard = ObjectAnimationToHide(MyStoryBoardTimeL, this.BorderUp.Height, 0);
  530. Mystoryboard.Completed += new EventHandler(BorderUpHide_Complete);
  531. Mystoryboard.Begin();
  532. }
  533. }
  534. private void BorderUpHide_Complete(object sender, EventArgs e)
  535. {
  536. Storyboard Mystoryboard = new Storyboard();
  537. Mystoryboard = SetBackSizeChangeAnimation(MyStoryBoardTimeL, objSize, Direction, 100);
  538. Mystoryboard.Completed += new EventHandler(Mystoryboard_Completed);
  539. Mystoryboard.Begin();
  540. }
  541. private Storyboard ObjectAnimationToHide(int time, double from, double to)
  542. {
  543. Storyboard ResultStoryboard = new Storyboard();
  544. DoubleAnimation dbOffset = new DoubleAnimation()
  545. {
  546. Duration = TimeSpan.FromMilliseconds(time),
  547. EasingFunction = new CircleEase()
  548. {
  549. EasingMode = EasingMode.EaseOut,
  550. },
  551. From = this.Width,
  552. To = to
  553. };
  554. ThicknessAnimation dbMargin = new ThicknessAnimation()
  555. {
  556. Duration = TimeSpan.FromMilliseconds(time),
  557. EasingFunction = new ExponentialEase()
  558. {
  559. EasingMode = EasingMode.EaseOut,
  560. },
  561. From = new Thickness(this.BorderDown.Margin.Left, 0, 0, 0),
  562. To = new Thickness(this.BorderDown.Margin.Left, 0, 0, -borderdownheight)
  563. };
  564. Storyboard.SetTarget(dbOffset, this.BorderUp);
  565. Storyboard.SetTarget(dbMargin, this.BorderUp);
  566. Storyboard.SetTargetProperty(dbOffset, new PropertyPath(Grid.HeightProperty));
  567. Storyboard.SetTargetProperty(dbMargin, new PropertyPath(Grid.MarginProperty));
  568. ResultStoryboard.BeginTime = TimeSpan.FromMilliseconds(delayTime);
  569. ResultStoryboard.Children.Add(dbOffset);
  570. ResultStoryboard.Children.Add(dbMargin);
  571. ResultStoryboard.FillBehavior = FillBehavior.HoldEnd;
  572. return ResultStoryboard;
  573. }
  574. #endregion
  575. private Storyboard SetBackSizeChangeAnimation(int time, ObjectSize objectsize, string Direction, int delaytime)
  576. {
  577. Storyboard ResultStoryboard = new Storyboard();
  578. double size = 0.0;
  579. double pos = 0.0;
  580. GetTargetSizeAndPos(objectsize, ref size, ref pos);
  581. DoubleAnimation dbOffset = new DoubleAnimation()
  582. {
  583. Duration = TimeSpan.FromMilliseconds(time),
  584. EasingFunction = new ExponentialEase()
  585. {
  586. EasingMode = EasingMode.EaseIn,
  587. Exponent = 0.3
  588. },
  589. From = this.Width,
  590. To = size
  591. };
  592. ThicknessAnimation dbMargin = new ThicknessAnimation()
  593. {
  594. Duration = TimeSpan.FromMilliseconds(time),
  595. EasingFunction = new ExponentialEase()
  596. {
  597. EasingMode = EasingMode.EaseIn,
  598. Exponent = 0.3
  599. },
  600. From = this.Margin,
  601. To = new Thickness(pos, 0, 0, this.Margin.Bottom)
  602. };
  603. Storyboard.SetTarget(dbOffset, (DependencyObject)this);
  604. Storyboard.SetTargetProperty(dbOffset, new PropertyPath(Grid.WidthProperty));
  605. ResultStoryboard.Children.Add(dbOffset);
  606. Storyboard.SetTarget(dbMargin, (DependencyObject)this);
  607. Storyboard.SetTargetProperty(dbMargin, new PropertyPath(Grid.MarginProperty));
  608. ResultStoryboard.Children.Add(dbMargin);
  609. ResultStoryboard.BeginTime = TimeSpan.FromMilliseconds(delaytime);
  610. ResultStoryboard.FillBehavior = FillBehavior.HoldEnd;
  611. return ResultStoryboard;
  612. }
  613. private Storyboard SetOriginalChangeAnimation(int time, int ToValue)
  614. {
  615. Storyboard ResultStoryboard = new Storyboard();
  616. DoubleAnimation dbOffset = new DoubleAnimation()
  617. {
  618. Duration = TimeSpan.FromMilliseconds(time),
  619. EasingFunction = new ExponentialEase()
  620. {
  621. EasingMode = EasingMode.EaseIn,
  622. Exponent = 0.3
  623. },
  624. From = this.Width,
  625. To = ToValue
  626. };
  627. ThicknessAnimation dbMargin = new ThicknessAnimation()
  628. {
  629. Duration = TimeSpan.FromMilliseconds(time),
  630. EasingFunction = new ExponentialEase()
  631. {
  632. EasingMode = EasingMode.EaseIn,
  633. Exponent = 0.3
  634. },
  635. From = this.Margin,
  636. To = new Thickness(this.Margin.Left + Math.Abs(this.Width - ToValue) / 2, 0, 0, this.Margin.Bottom)
  637. };
  638. Storyboard.SetTarget(dbOffset, (DependencyObject)this);
  639. Storyboard.SetTarget(dbMargin, (DependencyObject)this);
  640. Storyboard.SetTargetProperty(dbOffset, new PropertyPath(Grid.WidthProperty));
  641. Storyboard.SetTargetProperty(dbMargin, new PropertyPath(Grid.MarginProperty));
  642. ResultStoryboard.Children.Add(dbOffset);
  643. ResultStoryboard.Children.Add(dbMargin);
  644. ResultStoryboard.BeginTime = TimeSpan.FromMilliseconds(delayTime);
  645. ResultStoryboard.FillBehavior = FillBehavior.HoldEnd;
  646. return ResultStoryboard;
  647. }
  648. }
  649. }