Program.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using System.Linq;
  5. using System.IO;
  6. using System.Reactive.Linq;
  7. using Perspex;
  8. using Perspex.Animation;
  9. using Perspex.Collections;
  10. using Perspex.Controls;
  11. using Perspex.Controls.Html;
  12. using Perspex.Controls.Primitives;
  13. using Perspex.Controls.Shapes;
  14. using Perspex.Controls.Templates;
  15. using Perspex.Diagnostics;
  16. using Perspex.Layout;
  17. using Perspex.Media;
  18. using Perspex.Media.Imaging;
  19. #if PERSPEX_GTK
  20. using Perspex.Gtk;
  21. #endif
  22. using ReactiveUI;
  23. namespace TestApplication
  24. {
  25. internal class Program
  26. {
  27. private static readonly PerspexList<Node> s_treeData = new PerspexList<Node>
  28. {
  29. new Node
  30. {
  31. Name = "Root 1",
  32. Children = new PerspexList<Node>
  33. {
  34. new Node
  35. {
  36. Name = "Child 1",
  37. },
  38. new Node
  39. {
  40. Name = "Child 2",
  41. Children = new PerspexList<Node>
  42. {
  43. new Node
  44. {
  45. Name = "Grandchild 1",
  46. },
  47. new Node
  48. {
  49. Name = "Grandmaster Flash",
  50. },
  51. }
  52. },
  53. new Node
  54. {
  55. Name = "Child 3",
  56. },
  57. }
  58. },
  59. new Node
  60. {
  61. Name = "Root 2",
  62. },
  63. };
  64. private static readonly PerspexList<Item> s_listBoxData = new PerspexList<Item>
  65. {
  66. new Item { Name = "Item 1", Value = "Item 1 Value" },
  67. new Item { Name = "Item 2", Value = "Item 2 Value" },
  68. new Item { Name = "Item 3", Value = "Item 3 Value" },
  69. new Item { Name = "Item 4", Value = "Item 4 Value" },
  70. new Item { Name = "Item 5", Value = "Item 5 Value" },
  71. new Item { Name = "Item 6", Value = "Item 6 Value" },
  72. new Item { Name = "Item 7", Value = "Item 7 Value" },
  73. new Item { Name = "Item 8", Value = "Item 8 Value" },
  74. };
  75. private static void Main(string[] args)
  76. {
  77. // The version of ReactiveUI currently included is for WPF and so expects a WPF
  78. // dispatcher. This makes sure it's initialized.
  79. System.Windows.Threading.Dispatcher foo = System.Windows.Threading.Dispatcher.CurrentDispatcher;
  80. new App
  81. {
  82. DataTemplates = new DataTemplates
  83. {
  84. new TreeDataTemplate<Node>(
  85. x => new TextBlock { Text = x.Name },
  86. x => x.Children,
  87. x => true),
  88. },
  89. };
  90. TabControl container;
  91. Window window = new Window
  92. {
  93. Title = "Perspex Test Application",
  94. Width = 900,
  95. Height = 480,
  96. Content = new Grid
  97. {
  98. ColumnDefinitions = new ColumnDefinitions
  99. {
  100. new ColumnDefinition(1, GridUnitType.Star),
  101. new ColumnDefinition(1, GridUnitType.Star),
  102. },
  103. RowDefinitions = new RowDefinitions
  104. {
  105. new RowDefinition(GridLength.Auto),
  106. new RowDefinition(1, GridUnitType.Star),
  107. new RowDefinition(GridLength.Auto),
  108. },
  109. Children = new Controls
  110. {
  111. (container = new TabControl
  112. {
  113. Padding = new Thickness(5),
  114. Items = new[]
  115. {
  116. ButtonsTab(),
  117. TextTab(),
  118. HtmlTab(),
  119. ImagesTab(),
  120. ListsTab(),
  121. LayoutTab(),
  122. AnimationsTab(),
  123. },
  124. Transition = new CrossFade(TimeSpan.FromSeconds(0.25)),
  125. [Grid.RowProperty] = 1,
  126. [Grid.ColumnSpanProperty] = 2,
  127. })
  128. }
  129. },
  130. };
  131. container.Classes.Add(":container");
  132. window.Show();
  133. Application.Current.Run(window);
  134. }
  135. private static TabItem ButtonsTab()
  136. {
  137. var result = new TabItem
  138. {
  139. Header = "Button",
  140. Content = new ScrollViewer()
  141. {
  142. CanScrollHorizontally = false,
  143. Content = new StackPanel
  144. {
  145. Margin = new Thickness(10),
  146. Orientation = Orientation.Vertical,
  147. Gap = 4,
  148. Children = new Controls
  149. {
  150. new TextBlock
  151. {
  152. Text = "Button",
  153. FontWeight = FontWeight.Medium,
  154. FontSize = 20,
  155. Foreground = SolidColorBrush.Parse("#212121"),
  156. },
  157. new TextBlock
  158. {
  159. Text = "A button control",
  160. FontSize = 13,
  161. Foreground = SolidColorBrush.Parse("#727272"),
  162. Margin = new Thickness(0, 0, 0, 10)
  163. },
  164. new Button
  165. {
  166. Width = 150,
  167. Content = "Button"
  168. },
  169. new Button
  170. {
  171. Width = 150,
  172. Content = "Disabled",
  173. IsEnabled = false,
  174. },
  175. new TextBlock
  176. {
  177. Margin = new Thickness(0, 40, 0, 0),
  178. Text = "ToggleButton",
  179. FontWeight = FontWeight.Medium,
  180. FontSize = 20,
  181. Foreground = SolidColorBrush.Parse("#212121"),
  182. },
  183. new TextBlock
  184. {
  185. Text = "A toggle button control",
  186. FontSize = 13,
  187. Foreground = SolidColorBrush.Parse("#727272"),
  188. Margin = new Thickness(0, 0, 0, 10)
  189. },
  190. new ToggleButton
  191. {
  192. Width = 150,
  193. IsChecked = true,
  194. Content = "On"
  195. },
  196. new ToggleButton
  197. {
  198. Width = 150,
  199. IsChecked = false,
  200. Content = "Off"
  201. },
  202. }
  203. }
  204. },
  205. };
  206. return result;
  207. }
  208. private static TabItem HtmlTab()
  209. {
  210. return new TabItem
  211. {
  212. Header = "Text",
  213. Content = new ScrollViewer()
  214. {
  215. CanScrollHorizontally = false,
  216. Content = new StackPanel()
  217. {
  218. Margin = new Thickness(10),
  219. Orientation = Orientation.Vertical,
  220. Gap = 4,
  221. Children = new Controls
  222. {
  223. new TextBlock
  224. {
  225. Text = "TextBlock",
  226. FontWeight = FontWeight.Medium,
  227. FontSize = 20,
  228. Foreground = SolidColorBrush.Parse("#212121"),
  229. },
  230. new TextBlock
  231. {
  232. Text = "A control for displaying text.",
  233. FontSize = 13,
  234. Foreground = SolidColorBrush.Parse("#727272"),
  235. Margin = new Thickness(0, 0, 0, 10)
  236. },
  237. new TextBlock
  238. {
  239. Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
  240. FontSize = 11
  241. },
  242. new TextBlock
  243. {
  244. Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
  245. FontSize = 11,
  246. FontWeight = FontWeight.Medium
  247. },
  248. new TextBlock
  249. {
  250. Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
  251. FontSize = 11,
  252. FontWeight = FontWeight.Bold
  253. },
  254. new TextBlock
  255. {
  256. Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
  257. FontSize = 11,
  258. FontStyle = FontStyle.Italic,
  259. },
  260. new TextBlock
  261. {
  262. Margin = new Thickness(0, 40, 0, 0),
  263. Text = "HtmlLabel",
  264. FontWeight = FontWeight.Medium,
  265. FontSize = 20,
  266. Foreground = SolidColorBrush.Parse("#212121"),
  267. },
  268. new TextBlock
  269. {
  270. Text = "A label capable of displaying HTML content",
  271. FontSize = 13,
  272. Foreground = SolidColorBrush.Parse("#727272"),
  273. Margin = new Thickness(0, 0, 0, 10)
  274. },
  275. new HtmlLabel
  276. {
  277. Background = SolidColorBrush.Parse("#CCCCCC"),
  278. Padding = new Thickness(5),
  279. Text = @"<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. <a href=""#"">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
  280. <h2>Header Level 2</h2>
  281. <ol>
  282. <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
  283. <li>Aliquam tincidunt mauris eu risus.</li>
  284. </ol>
  285. <blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote>
  286. <h3>Header Level 3</h3>
  287. <ul>
  288. <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
  289. <li>Aliquam tincidunt mauris eu risus.</li>
  290. </ul>"
  291. }
  292. }
  293. }
  294. }
  295. };
  296. }
  297. private static TabItem TextTab()
  298. {
  299. return new TabItem
  300. {
  301. Header = "Input",
  302. Content = new ScrollViewer()
  303. {
  304. Content = new StackPanel
  305. {
  306. Margin = new Thickness(10),
  307. Orientation = Orientation.Vertical,
  308. Gap = 4,
  309. Children = new Controls
  310. {
  311. new TextBlock
  312. {
  313. Text = "TextBox",
  314. FontWeight = FontWeight.Medium,
  315. FontSize = 20,
  316. Foreground = SolidColorBrush.Parse("#212121"),
  317. },
  318. new TextBlock
  319. {
  320. Text = "A text box control",
  321. FontSize = 13,
  322. Foreground = SolidColorBrush.Parse("#727272"),
  323. Margin = new Thickness(0, 0, 0, 10)
  324. },
  325. new TextBox { Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", Width = 200 },
  326. new TextBox { AcceptsReturn = true, TextWrapping = TextWrapping.Wrap, Width = 200, Height = 150, Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." },
  327. new TextBlock
  328. {
  329. Margin = new Thickness(0, 40, 0, 0),
  330. Text = "CheckBox",
  331. FontWeight = FontWeight.Medium,
  332. FontSize = 20,
  333. Foreground = SolidColorBrush.Parse("#212121"),
  334. },
  335. new TextBlock
  336. {
  337. Text = "A check box control",
  338. FontSize = 13,
  339. Foreground = SolidColorBrush.Parse("#727272"),
  340. Margin = new Thickness(0, 0, 0, 10)
  341. },
  342. new CheckBox { IsChecked = true, Margin = new Thickness(0, 0, 0, 5), Content = "Checked" },
  343. new CheckBox { IsChecked = false, Content = "Unchecked" },
  344. new TextBlock
  345. {
  346. Margin = new Thickness(0, 40, 0, 0),
  347. Text = "RadioButton",
  348. FontWeight = FontWeight.Medium,
  349. FontSize = 20,
  350. Foreground = SolidColorBrush.Parse("#212121"),
  351. },
  352. new TextBlock
  353. {
  354. Text = "A radio button control",
  355. FontSize = 13,
  356. Foreground = SolidColorBrush.Parse("#727272"),
  357. Margin = new Thickness(0, 0, 0, 10)
  358. },
  359. new RadioButton { IsChecked = true, Content = "Option 1" },
  360. new RadioButton { IsChecked = false, Content = "Option 2" },
  361. new RadioButton { IsChecked = false, Content = "Option 3" },
  362. }
  363. }
  364. }
  365. };
  366. }
  367. private static TabItem ListsTab()
  368. {
  369. return new TabItem
  370. {
  371. Header = "Lists",
  372. Content = new ScrollViewer()
  373. {
  374. CanScrollHorizontally = false,
  375. Content = new StackPanel
  376. {
  377. HorizontalAlignment = HorizontalAlignment.Left,
  378. Orientation = Orientation.Vertical,
  379. VerticalAlignment = VerticalAlignment.Top,
  380. Gap = 4,
  381. Margin = new Thickness(10),
  382. DataTemplates = new DataTemplates
  383. {
  384. new DataTemplate<Item>(x =>
  385. new StackPanel
  386. {
  387. Gap = 4,
  388. Orientation = Orientation.Horizontal,
  389. Children = new Controls
  390. {
  391. new Image { Width = 50, Height = 50, Source = new Bitmap("github_icon.png") },
  392. new TextBlock { Text = x.Name, FontSize = 18 }
  393. }
  394. })
  395. },
  396. Children = new Controls
  397. {
  398. new TextBlock
  399. {
  400. Text = "ListBox",
  401. FontWeight = FontWeight.Medium,
  402. FontSize = 20,
  403. Foreground = SolidColorBrush.Parse("#212121"),
  404. },
  405. new TextBlock
  406. {
  407. Text = "A list box control.",
  408. FontSize = 13,
  409. Foreground = SolidColorBrush.Parse("#727272"),
  410. Margin = new Thickness(0, 0, 0, 10)
  411. },
  412. new ListBox
  413. {
  414. BorderThickness = 2,
  415. Items = s_listBoxData,
  416. Height = 300,
  417. Width = 300,
  418. },
  419. new TextBlock
  420. {
  421. Margin = new Thickness(0, 40, 0, 0),
  422. Text = "TreeView",
  423. FontWeight = FontWeight.Medium,
  424. FontSize = 20,
  425. Foreground = SolidColorBrush.Parse("#212121"),
  426. },
  427. new TextBlock
  428. {
  429. Text = "A tree view control.",
  430. FontSize = 13,
  431. Foreground = SolidColorBrush.Parse("#727272"),
  432. Margin = new Thickness(0, 0, 0, 10)
  433. },
  434. new TreeView
  435. {
  436. Name = "treeView",
  437. Items = s_treeData,
  438. Height = 300,
  439. BorderThickness = 2,
  440. Width = 300,
  441. }
  442. }
  443. },
  444. }
  445. };
  446. }
  447. private static TabItem ImagesTab()
  448. {
  449. var imageDeck = new Deck
  450. {
  451. Width = 400,
  452. Height = 400,
  453. Transition = new PageSlide(TimeSpan.FromSeconds(0.25)),
  454. Items = new[]
  455. {
  456. new Image { Source = new Bitmap("github_icon.png"), Width = 400, Height = 400 },
  457. new Image { Source = new Bitmap("pattern.jpg"), Width = 400, Height = 400 },
  458. }
  459. };
  460. imageDeck.AutoSelect = true;
  461. var next = new Button
  462. {
  463. VerticalAlignment = VerticalAlignment.Center,
  464. Padding = new Thickness(20),
  465. Content = new Perspex.Controls.Shapes.Path
  466. {
  467. Data = StreamGeometry.Parse("M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z"),
  468. Fill = Brushes.Black
  469. }
  470. };
  471. var prev = new Button
  472. {
  473. VerticalAlignment = VerticalAlignment.Center,
  474. Padding = new Thickness(20),
  475. Content = new Perspex.Controls.Shapes.Path
  476. {
  477. Data = StreamGeometry.Parse("M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"),
  478. Fill = Brushes.Black
  479. }
  480. };
  481. prev.Click += (s, e) =>
  482. {
  483. if (imageDeck.SelectedIndex == 0)
  484. imageDeck.SelectedIndex = 1;
  485. else
  486. imageDeck.SelectedIndex--;
  487. };
  488. next.Click += (s, e) =>
  489. {
  490. if (imageDeck.SelectedIndex == 1)
  491. imageDeck.SelectedIndex = 0;
  492. else
  493. imageDeck.SelectedIndex++;
  494. };
  495. return new TabItem
  496. {
  497. Header = "Images",
  498. Content = new ScrollViewer
  499. {
  500. Content = new StackPanel
  501. {
  502. HorizontalAlignment = HorizontalAlignment.Left,
  503. Orientation = Orientation.Vertical,
  504. VerticalAlignment = VerticalAlignment.Top,
  505. Gap = 4,
  506. Margin = new Thickness(10),
  507. Children = new Controls
  508. {
  509. new TextBlock
  510. {
  511. Text = "Deck",
  512. FontWeight = FontWeight.Medium,
  513. FontSize = 20,
  514. Foreground = SolidColorBrush.Parse("#212121"),
  515. },
  516. new TextBlock
  517. {
  518. Text = "An items control that displays its items as pages that fill the controls.",
  519. FontSize = 13,
  520. Foreground = SolidColorBrush.Parse("#727272"),
  521. Margin = new Thickness(0, 0, 0, 10)
  522. },
  523. new StackPanel
  524. {
  525. Name = "deckVisual",
  526. Orientation = Orientation.Horizontal,
  527. Gap = 4,
  528. Children = new Controls
  529. {
  530. prev,
  531. imageDeck,
  532. next
  533. }
  534. }
  535. }
  536. }
  537. }
  538. };
  539. }
  540. private static TabItem LayoutTab()
  541. {
  542. return new TabItem
  543. {
  544. Header = "Layout",
  545. Content = new ScrollViewer
  546. {
  547. Content = new StackPanel
  548. {
  549. HorizontalAlignment = HorizontalAlignment.Left,
  550. Orientation = Orientation.Vertical,
  551. VerticalAlignment = VerticalAlignment.Top,
  552. Gap = 4,
  553. Margin = new Thickness(10),
  554. Children = new Controls
  555. {
  556. new TextBlock
  557. {
  558. Text = "Grid",
  559. FontWeight = FontWeight.Medium,
  560. FontSize = 20,
  561. Foreground = SolidColorBrush.Parse("#212121"),
  562. },
  563. new TextBlock
  564. {
  565. Text = "Lays out child controls according to a grid.",
  566. FontSize = 13,
  567. Foreground = SolidColorBrush.Parse("#727272"),
  568. Margin = new Thickness(0, 0, 0, 10)
  569. },
  570. new Grid
  571. {
  572. Width = 600,
  573. ColumnDefinitions = new ColumnDefinitions
  574. {
  575. new ColumnDefinition(1, GridUnitType.Star),
  576. new ColumnDefinition(1, GridUnitType.Star),
  577. },
  578. RowDefinitions = new RowDefinitions
  579. {
  580. new RowDefinition(1, GridUnitType.Auto),
  581. new RowDefinition(1, GridUnitType.Auto)
  582. },
  583. Children = new Controls
  584. {
  585. new Rectangle
  586. {
  587. Fill = SolidColorBrush.Parse("#FF5722"),
  588. [Grid.ColumnSpanProperty] = 2,
  589. Height = 200,
  590. Margin = new Thickness(2.5)
  591. },
  592. new Rectangle
  593. {
  594. Fill = SolidColorBrush.Parse("#FF5722"),
  595. [Grid.RowProperty] = 1,
  596. Height = 100,
  597. Margin = new Thickness(2.5)
  598. },
  599. new Rectangle
  600. {
  601. Fill = SolidColorBrush.Parse("#FF5722"),
  602. [Grid.RowProperty] = 1,
  603. [Grid.ColumnProperty] = 1,
  604. Height = 100,
  605. Margin = new Thickness(2.5)
  606. },
  607. },
  608. },
  609. new TextBlock
  610. {
  611. Margin = new Thickness(0, 40, 0, 0),
  612. Text = "StackPanel",
  613. FontWeight = FontWeight.Medium,
  614. FontSize = 20,
  615. Foreground = SolidColorBrush.Parse("#212121"),
  616. },
  617. new TextBlock
  618. {
  619. Text = "A panel which lays out its children horizontally or vertically.",
  620. FontSize = 13,
  621. Foreground = SolidColorBrush.Parse("#727272"),
  622. Margin = new Thickness(0, 0, 0, 10)
  623. },
  624. new StackPanel
  625. {
  626. Orientation = Orientation.Vertical,
  627. Gap = 4,
  628. Width = 300,
  629. Children = new Controls
  630. {
  631. new Rectangle
  632. {
  633. Fill = SolidColorBrush.Parse("#FFC107"),
  634. Height = 50,
  635. },
  636. new Rectangle
  637. {
  638. Fill = SolidColorBrush.Parse("#FFC107"),
  639. Height = 50,
  640. },
  641. new Rectangle
  642. {
  643. Fill = SolidColorBrush.Parse("#FFC107"),
  644. Height = 50,
  645. },
  646. }
  647. },
  648. }
  649. }
  650. }
  651. };
  652. }
  653. private static TabItem AnimationsTab()
  654. {
  655. Border border1;
  656. Border border2;
  657. RotateTransform rotate;
  658. Button button1;
  659. var result = new TabItem
  660. {
  661. Header = "Animations",
  662. Content = new StackPanel
  663. {
  664. HorizontalAlignment = HorizontalAlignment.Left,
  665. Orientation = Orientation.Vertical,
  666. VerticalAlignment = VerticalAlignment.Top,
  667. Gap = 4,
  668. Margin = new Thickness(10),
  669. Children = new Controls
  670. {
  671. new TextBlock
  672. {
  673. Text = "Animations",
  674. FontWeight = FontWeight.Medium,
  675. FontSize = 20,
  676. Foreground = SolidColorBrush.Parse("#212121"),
  677. },
  678. new TextBlock
  679. {
  680. Text = "A few animations showcased below",
  681. FontSize = 13,
  682. Foreground = SolidColorBrush.Parse("#727272"),
  683. Margin = new Thickness(0, 0, 0, 10)
  684. },
  685. (button1 = new Button
  686. {
  687. Content = "Animate",
  688. Width = 120,
  689. [Grid.ColumnProperty] = 1,
  690. [Grid.RowProperty] = 1,
  691. }),
  692. new Canvas
  693. {
  694. Children = new Controls
  695. {
  696. (border1 = new Border
  697. {
  698. Width = 100,
  699. Height = 100,
  700. HorizontalAlignment = HorizontalAlignment.Center,
  701. VerticalAlignment = VerticalAlignment.Center,
  702. Background = Brushes.Crimson,
  703. RenderTransform = new RotateTransform(),
  704. Child = new TextBox
  705. {
  706. Background = Brushes.White,
  707. Text = "Hello!",
  708. HorizontalAlignment = HorizontalAlignment.Center,
  709. VerticalAlignment = VerticalAlignment.Center,
  710. },
  711. [Canvas.LeftProperty] = 100,
  712. [Canvas.TopProperty] = 100,
  713. }),
  714. (border2 = new Border
  715. {
  716. Width = 100,
  717. Height = 100,
  718. HorizontalAlignment = HorizontalAlignment.Center,
  719. VerticalAlignment = VerticalAlignment.Center,
  720. Background = Brushes.Coral,
  721. Child = new Image
  722. {
  723. Source = new Bitmap("github_icon.png"),
  724. HorizontalAlignment = HorizontalAlignment.Center,
  725. VerticalAlignment = VerticalAlignment.Center,
  726. },
  727. RenderTransform = (rotate = new RotateTransform
  728. {
  729. PropertyTransitions = new PropertyTransitions
  730. {
  731. RotateTransform.AngleProperty.Transition(500),
  732. }
  733. }),
  734. PropertyTransitions = new PropertyTransitions
  735. {
  736. Layoutable.WidthProperty.Transition(300),
  737. Layoutable.HeightProperty.Transition(1000),
  738. },
  739. [Canvas.LeftProperty] = 400,
  740. [Canvas.TopProperty] = 100,
  741. }),
  742. }
  743. }
  744. },
  745. },
  746. };
  747. button1.Click += (s, e) =>
  748. {
  749. if (border2.Width == 100)
  750. {
  751. border2.Width = border2.Height = 400;
  752. rotate.Angle = 180;
  753. }
  754. else
  755. {
  756. border2.Width = border2.Height = 100;
  757. rotate.Angle = 0;
  758. }
  759. };
  760. var start = Animate.Stopwatch.Elapsed;
  761. var degrees = Animate.Timer
  762. .Select(x =>
  763. {
  764. var elapsed = (x - start).TotalSeconds;
  765. var cycles = elapsed / 4;
  766. var progress = cycles % 1;
  767. return 360.0 * progress;
  768. });
  769. border1.RenderTransform.Bind(
  770. RotateTransform.AngleProperty,
  771. degrees,
  772. BindingPriority.Animation);
  773. return result;
  774. }
  775. }
  776. }