MainWindow.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reactive.Linq;
  5. using System.Text;
  6. using Avalonia;
  7. using Avalonia.Animation;
  8. using Avalonia.Collections;
  9. using Avalonia.Controls;
  10. using Avalonia.Controls.Html;
  11. using Avalonia.Controls.Primitives;
  12. using Avalonia.Controls.Shapes;
  13. using Avalonia.Controls.Templates;
  14. using Avalonia.Data;
  15. using Avalonia.Diagnostics;
  16. using Avalonia.Layout;
  17. using Avalonia.Media;
  18. using Avalonia.Media.Imaging;
  19. using Avalonia.Platform;
  20. using Avalonia.Threading;
  21. using TestApplication;
  22. namespace TestApplication
  23. {
  24. class MainWindow
  25. {
  26. private static readonly AvaloniaList<Node> s_treeData = new AvaloniaList<Node>
  27. {
  28. new Node
  29. {
  30. Name = "Root 1",
  31. Children = new AvaloniaList<Node>
  32. {
  33. new Node
  34. {
  35. Name = "Child 1",
  36. },
  37. new Node
  38. {
  39. Name = "Child 2",
  40. Children = new AvaloniaList<Node>
  41. {
  42. new Node
  43. {
  44. Name = "Grandchild 1",
  45. },
  46. new Node
  47. {
  48. Name = "Grandmaster Flash",
  49. },
  50. }
  51. },
  52. new Node
  53. {
  54. Name = "Child 3",
  55. },
  56. }
  57. },
  58. new Node
  59. {
  60. Name = "Root 2",
  61. },
  62. };
  63. private static readonly AvaloniaList<Item> s_listBoxData = new AvaloniaList<Item>
  64. {
  65. new Item { Name = "Item 1", Value = "Item 1 Value" },
  66. new Item { Name = "Item 2", Value = "Item 2 Value" },
  67. new Item { Name = "Item 3", Value = "Item 3 Value" },
  68. new Item { Name = "Item 4", Value = "Item 4 Value" },
  69. new Item { Name = "Item 5", Value = "Item 5 Value" },
  70. new Item { Name = "Item 6", Value = "Item 6 Value" },
  71. new Item { Name = "Item 7", Value = "Item 7 Value" },
  72. new Item { Name = "Item 8", Value = "Item 8 Value" },
  73. };
  74. public static Window Create()
  75. {
  76. TabControl container;
  77. Window window = new Window
  78. {
  79. Title = "Avalonia Test Application",
  80. //Width = 900,
  81. //Height = 480,
  82. Content = (container = new TabControl
  83. {
  84. Padding = new Thickness(5),
  85. Items = new[]
  86. {
  87. ButtonsTab(),
  88. TextTab(),
  89. HtmlTab(),
  90. ImagesTab(),
  91. ListsTab(),
  92. LayoutTab(),
  93. AnimationsTab(),
  94. },
  95. Transition = new CrossFade(TimeSpan.FromSeconds(0.25)),
  96. [Grid.RowProperty] = 1,
  97. [Grid.ColumnSpanProperty] = 2,
  98. })
  99. };
  100. container.Classes.Add("container");
  101. window.Show();
  102. return window;
  103. }
  104. private static TabItem ButtonsTab()
  105. {
  106. var result = new TabItem
  107. {
  108. Header = "Button",
  109. Content = new ScrollViewer()
  110. {
  111. CanScrollHorizontally = false,
  112. Content = new StackPanel
  113. {
  114. Margin = new Thickness(10),
  115. Orientation = Orientation.Vertical,
  116. Gap = 4,
  117. Children = new Controls
  118. {
  119. new TextBlock
  120. {
  121. Text = "Button",
  122. FontWeight = FontWeight.Medium,
  123. FontSize = 20,
  124. Foreground = Brush.Parse("#212121"),
  125. },
  126. new TextBlock
  127. {
  128. Text = "A button control",
  129. FontSize = 13,
  130. Foreground = Brush.Parse("#727272"),
  131. Margin = new Thickness(0, 0, 0, 10)
  132. },
  133. new Button
  134. {
  135. Width = 150,
  136. Content = "Button"
  137. },
  138. new Button
  139. {
  140. Width = 150,
  141. Content = "Disabled",
  142. IsEnabled = false,
  143. },
  144. new TextBlock
  145. {
  146. Margin = new Thickness(0, 40, 0, 0),
  147. Text = "ToggleButton",
  148. FontWeight = FontWeight.Medium,
  149. FontSize = 20,
  150. Foreground = Brush.Parse("#212121"),
  151. },
  152. new TextBlock
  153. {
  154. Text = "A toggle button control",
  155. FontSize = 13,
  156. Foreground = Brush.Parse("#727272"),
  157. Margin = new Thickness(0, 0, 0, 10)
  158. },
  159. new ToggleButton
  160. {
  161. Width = 150,
  162. IsChecked = true,
  163. Content = "On"
  164. },
  165. new ToggleButton
  166. {
  167. Width = 150,
  168. IsChecked = false,
  169. Content = "Off"
  170. },
  171. }
  172. }
  173. },
  174. };
  175. return result;
  176. }
  177. private static TabItem HtmlTab()
  178. {
  179. return new TabItem
  180. {
  181. Header = "Text",
  182. Content = new ScrollViewer()
  183. {
  184. CanScrollHorizontally = false,
  185. Content = new StackPanel()
  186. {
  187. Margin = new Thickness(10),
  188. Orientation = Orientation.Vertical,
  189. Gap = 4,
  190. Children = new Controls
  191. {
  192. new TextBlock
  193. {
  194. Text = "TextBlock",
  195. FontWeight = FontWeight.Medium,
  196. FontSize = 20,
  197. Foreground = Brush.Parse("#212121"),
  198. },
  199. new TextBlock
  200. {
  201. Text = "A control for displaying text.",
  202. FontSize = 13,
  203. Foreground = Brush.Parse("#727272"),
  204. Margin = new Thickness(0, 0, 0, 10)
  205. },
  206. new TextBlock
  207. {
  208. Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
  209. FontSize = 11
  210. },
  211. new TextBlock
  212. {
  213. Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
  214. FontSize = 11,
  215. FontWeight = FontWeight.Medium
  216. },
  217. new TextBlock
  218. {
  219. Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
  220. FontSize = 11,
  221. FontWeight = FontWeight.Bold
  222. },
  223. new TextBlock
  224. {
  225. Text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
  226. FontSize = 11,
  227. FontStyle = FontStyle.Italic,
  228. },
  229. new TextBlock
  230. {
  231. Margin = new Thickness(0, 40, 0, 0),
  232. Text = "HtmlLabel",
  233. FontWeight = FontWeight.Medium,
  234. FontSize = 20,
  235. Foreground = Brush.Parse("#212121"),
  236. },
  237. new TextBlock
  238. {
  239. Text = "A label capable of displaying HTML content",
  240. FontSize = 13,
  241. Foreground = Brush.Parse("#727272"),
  242. Margin = new Thickness(0, 0, 0, 10)
  243. },
  244. new HtmlLabel
  245. {
  246. Background = Brush.Parse("#CCCCCC"),
  247. Padding = new Thickness(5),
  248. 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>
  249. <h2>Header Level 2</h2>
  250. <ol>
  251. <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
  252. <li>Aliquam tincidunt mauris eu risus.</li>
  253. </ol>
  254. <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>
  255. <h3>Header Level 3</h3>
  256. <ul>
  257. <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
  258. <li>Aliquam tincidunt mauris eu risus.</li>
  259. </ul>"
  260. }
  261. }
  262. }
  263. }
  264. };
  265. }
  266. private static TabItem TextTab()
  267. {
  268. return new TabItem
  269. {
  270. Header = "Input",
  271. Content = new ScrollViewer()
  272. {
  273. Content = new StackPanel
  274. {
  275. Margin = new Thickness(10),
  276. Orientation = Orientation.Vertical,
  277. Gap = 4,
  278. Children = new Controls
  279. {
  280. new TextBlock
  281. {
  282. Text = "TextBox",
  283. FontWeight = FontWeight.Medium,
  284. FontSize = 20,
  285. Foreground = Brush.Parse("#212121"),
  286. },
  287. new TextBlock
  288. {
  289. Text = "A text box control",
  290. FontSize = 13,
  291. Foreground = Brush.Parse("#727272"),
  292. Margin = new Thickness(0, 0, 0, 10)
  293. },
  294. new TextBox { Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", Width = 200},
  295. new TextBox { Width = 200, Watermark="Watermark"},
  296. new TextBox { Width = 200, Watermark="Floating Watermark", UseFloatingWatermark = true },
  297. 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." },
  298. new TextBlock
  299. {
  300. Margin = new Thickness(0, 40, 0, 0),
  301. Text = "CheckBox",
  302. FontWeight = FontWeight.Medium,
  303. FontSize = 20,
  304. Foreground = Brush.Parse("#212121"),
  305. },
  306. new TextBlock
  307. {
  308. Text = "A check box control",
  309. FontSize = 13,
  310. Foreground = Brush.Parse("#727272"),
  311. Margin = new Thickness(0, 0, 0, 10)
  312. },
  313. new CheckBox { IsChecked = true, Margin = new Thickness(0, 0, 0, 5), Content = "Checked" },
  314. new CheckBox { IsChecked = false, Content = "Unchecked" },
  315. new TextBlock
  316. {
  317. Margin = new Thickness(0, 40, 0, 0),
  318. Text = "RadioButton",
  319. FontWeight = FontWeight.Medium,
  320. FontSize = 20,
  321. Foreground = Brush.Parse("#212121"),
  322. },
  323. new TextBlock
  324. {
  325. Text = "A radio button control",
  326. FontSize = 13,
  327. Foreground = Brush.Parse("#727272"),
  328. Margin = new Thickness(0, 0, 0, 10)
  329. },
  330. new RadioButton { IsChecked = true, Content = "Option 1" },
  331. new RadioButton { IsChecked = false, Content = "Option 2" },
  332. new RadioButton { IsChecked = false, Content = "Option 3" },
  333. }
  334. }
  335. }
  336. };
  337. }
  338. public static string RootNamespace;
  339. static Stream GetImage(string path)
  340. {
  341. return AvaloniaLocator.Current.GetService<IAssetLoader>().Open(new Uri("resm:" + RootNamespace + "." + path));
  342. }
  343. private static TabItem ListsTab()
  344. {
  345. return new TabItem
  346. {
  347. Header = "Lists",
  348. Content = new ScrollViewer()
  349. {
  350. CanScrollHorizontally = false,
  351. Content = new StackPanel
  352. {
  353. HorizontalAlignment = HorizontalAlignment.Left,
  354. Orientation = Orientation.Vertical,
  355. VerticalAlignment = VerticalAlignment.Top,
  356. Gap = 4,
  357. Margin = new Thickness(10),
  358. DataTemplates = new DataTemplates
  359. {
  360. new FuncDataTemplate<Item>(x =>
  361. new StackPanel
  362. {
  363. Gap = 4,
  364. Orientation = Orientation.Horizontal,
  365. Children = new Controls
  366. {
  367. new Image { Width = 50, Height = 50, Source = new Bitmap(GetImage("github_icon.png")) },
  368. new TextBlock { Text = x.Name, FontSize = 18 }
  369. }
  370. })
  371. },
  372. Children = new Controls
  373. {
  374. new TextBlock
  375. {
  376. Text = "ListBox",
  377. FontWeight = FontWeight.Medium,
  378. FontSize = 20,
  379. Foreground = Brush.Parse("#212121"),
  380. },
  381. new TextBlock
  382. {
  383. Text = "A list box control.",
  384. FontSize = 13,
  385. Foreground = Brush.Parse("#727272"),
  386. Margin = new Thickness(0, 0, 0, 10)
  387. },
  388. new ListBox
  389. {
  390. BorderThickness = 2,
  391. Items = s_listBoxData,
  392. Height = 300,
  393. Width = 300,
  394. },
  395. new TextBlock
  396. {
  397. Margin = new Thickness(0, 40, 0, 0),
  398. Text = "TreeView",
  399. FontWeight = FontWeight.Medium,
  400. FontSize = 20,
  401. Foreground = Brush.Parse("#212121"),
  402. },
  403. new TextBlock
  404. {
  405. Text = "A tree view control.",
  406. FontSize = 13,
  407. Foreground = Brush.Parse("#727272"),
  408. Margin = new Thickness(0, 0, 0, 10)
  409. },
  410. new TreeView
  411. {
  412. Name = "treeView",
  413. Items = s_treeData,
  414. Height = 300,
  415. BorderThickness = 2,
  416. Width = 300,
  417. }
  418. }
  419. },
  420. }
  421. };
  422. }
  423. private static TabItem ImagesTab()
  424. {
  425. var imageCarousel = new Carousel
  426. {
  427. Width = 400,
  428. Height = 400,
  429. Transition = new PageSlide(TimeSpan.FromSeconds(0.25)),
  430. Items = new[]
  431. {
  432. new Image { Source = new Bitmap(GetImage("github_icon.png")), Width = 400, Height = 400 },
  433. new Image { Source = new Bitmap(GetImage("pattern.jpg")), Width = 400, Height = 400 },
  434. }
  435. };
  436. var next = new Button
  437. {
  438. VerticalAlignment = VerticalAlignment.Center,
  439. Padding = new Thickness(20),
  440. Content = new Avalonia.Controls.Shapes.Path
  441. {
  442. Data = StreamGeometry.Parse("M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z"),
  443. Fill = Brushes.Black
  444. }
  445. };
  446. var prev = new Button
  447. {
  448. VerticalAlignment = VerticalAlignment.Center,
  449. Padding = new Thickness(20),
  450. Content = new Avalonia.Controls.Shapes.Path
  451. {
  452. Data = StreamGeometry.Parse("M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"),
  453. Fill = Brushes.Black
  454. }
  455. };
  456. prev.Click += (s, e) =>
  457. {
  458. if (imageCarousel.SelectedIndex == 0)
  459. imageCarousel.SelectedIndex = 1;
  460. else
  461. imageCarousel.SelectedIndex--;
  462. };
  463. next.Click += (s, e) =>
  464. {
  465. if (imageCarousel.SelectedIndex == 1)
  466. imageCarousel.SelectedIndex = 0;
  467. else
  468. imageCarousel.SelectedIndex++;
  469. };
  470. return new TabItem
  471. {
  472. Header = "Images",
  473. Content = new ScrollViewer
  474. {
  475. Content = new StackPanel
  476. {
  477. HorizontalAlignment = HorizontalAlignment.Left,
  478. Orientation = Orientation.Vertical,
  479. VerticalAlignment = VerticalAlignment.Top,
  480. Gap = 4,
  481. Margin = new Thickness(10),
  482. Children = new Controls
  483. {
  484. new TextBlock
  485. {
  486. Text = "Carousel",
  487. FontWeight = FontWeight.Medium,
  488. FontSize = 20,
  489. Foreground = Brush.Parse("#212121"),
  490. },
  491. new TextBlock
  492. {
  493. Text = "An items control that displays its items as pages that fill the controls.",
  494. FontSize = 13,
  495. Foreground = Brush.Parse("#727272"),
  496. Margin = new Thickness(0, 0, 0, 10)
  497. },
  498. new StackPanel
  499. {
  500. Name = "carouselVisual",
  501. Orientation = Orientation.Horizontal,
  502. Gap = 4,
  503. Children = new Controls
  504. {
  505. prev,
  506. imageCarousel,
  507. next
  508. }
  509. }
  510. }
  511. }
  512. }
  513. };
  514. }
  515. private static TabItem LayoutTab()
  516. {
  517. var polylinePoints = new Point[] { new Point(0, 0), new Point(5, 0), new Point(6, -2), new Point(7, 3), new Point(8, -3),
  518. new Point(9, 1), new Point(10, 0), new Point(15, 0) };
  519. var polygonPoints = new Point[] { new Point(5, 0), new Point(8, 8), new Point(0, 3), new Point(10, 3), new Point(2, 8) };
  520. for (int i = 0; i < polylinePoints.Length; i++)
  521. {
  522. polylinePoints[i] = polylinePoints[i] * 13;
  523. }
  524. for (int i = 0; i < polygonPoints.Length; i++)
  525. {
  526. polygonPoints[i] = polygonPoints[i] * 15;
  527. }
  528. return new TabItem
  529. {
  530. Header = "Layout",
  531. Content = new ScrollViewer
  532. {
  533. Content = new StackPanel
  534. {
  535. HorizontalAlignment = HorizontalAlignment.Left,
  536. Orientation = Orientation.Vertical,
  537. VerticalAlignment = VerticalAlignment.Top,
  538. Gap = 4,
  539. Margin = new Thickness(10),
  540. Children = new Controls
  541. {
  542. new TextBlock
  543. {
  544. Text = "Grid",
  545. FontWeight = FontWeight.Medium,
  546. FontSize = 20,
  547. Foreground = Brush.Parse("#212121"),
  548. },
  549. new TextBlock
  550. {
  551. Text = "Lays out child controls according to a grid.",
  552. FontSize = 13,
  553. Foreground = Brush.Parse("#727272"),
  554. Margin = new Thickness(0, 0, 0, 10)
  555. },
  556. new Grid
  557. {
  558. Width = 600,
  559. ColumnDefinitions = new ColumnDefinitions
  560. {
  561. new ColumnDefinition(1, GridUnitType.Star),
  562. new ColumnDefinition(1, GridUnitType.Star),
  563. },
  564. RowDefinitions = new RowDefinitions
  565. {
  566. new RowDefinition(1, GridUnitType.Auto),
  567. new RowDefinition(1, GridUnitType.Auto)
  568. },
  569. Children = new Controls
  570. {
  571. new Rectangle
  572. {
  573. Fill = Brush.Parse("#FF5722"),
  574. [Grid.ColumnSpanProperty] = 2,
  575. Height = 200,
  576. Margin = new Thickness(2.5)
  577. },
  578. new Rectangle
  579. {
  580. Fill = Brush.Parse("#FF5722"),
  581. [Grid.RowProperty] = 1,
  582. Height = 100,
  583. Margin = new Thickness(2.5)
  584. },
  585. new Rectangle
  586. {
  587. Fill = Brush.Parse("#FF5722"),
  588. [Grid.RowProperty] = 1,
  589. [Grid.ColumnProperty] = 1,
  590. Height = 100,
  591. Margin = new Thickness(2.5)
  592. },
  593. },
  594. },
  595. new TextBlock
  596. {
  597. Margin = new Thickness(0, 40, 0, 0),
  598. Text = "StackPanel",
  599. FontWeight = FontWeight.Medium,
  600. FontSize = 20,
  601. Foreground = Brush.Parse("#212121"),
  602. },
  603. new TextBlock
  604. {
  605. Text = "A panel which lays out its children horizontally or vertically.",
  606. FontSize = 13,
  607. Foreground = Brush.Parse("#727272"),
  608. Margin = new Thickness(0, 0, 0, 10)
  609. },
  610. new StackPanel
  611. {
  612. Orientation = Orientation.Vertical,
  613. Gap = 4,
  614. Width = 300,
  615. Children = new Controls
  616. {
  617. new Rectangle
  618. {
  619. Fill = Brush.Parse("#FFC107"),
  620. Height = 50,
  621. },
  622. new Rectangle
  623. {
  624. Fill = Brush.Parse("#FFC107"),
  625. Height = 50,
  626. },
  627. new Rectangle
  628. {
  629. Fill = Brush.Parse("#FFC107"),
  630. Height = 50,
  631. },
  632. }
  633. },
  634. new TextBlock
  635. {
  636. Margin = new Thickness(0, 40, 0, 0),
  637. Text = "Canvas",
  638. FontWeight = FontWeight.Medium,
  639. FontSize = 20,
  640. Foreground = Brush.Parse("#212121"),
  641. },
  642. new TextBlock
  643. {
  644. Text = "A panel which lays out its children by explicit coordinates.",
  645. FontSize = 13,
  646. Foreground = Brush.Parse("#727272"),
  647. Margin = new Thickness(0, 0, 0, 10)
  648. },
  649. new Canvas
  650. {
  651. Background = Brushes.Yellow,
  652. Width = 300,
  653. Height = 400,
  654. Children = new Controls
  655. {
  656. new Rectangle
  657. {
  658. Fill = Brushes.Blue,
  659. Width = 63,
  660. Height = 41,
  661. [Canvas.LeftProperty] = 40,
  662. [Canvas.TopProperty] = 31,
  663. },
  664. new Ellipse
  665. {
  666. Fill = Brushes.Green,
  667. Width = 58,
  668. Height = 58,
  669. [Canvas.LeftProperty] = 130,
  670. [Canvas.TopProperty] = 79,
  671. },
  672. new Line
  673. {
  674. Stroke = Brushes.Red,
  675. StrokeThickness = 2,
  676. StartPoint = new Point(120, 185),
  677. EndPoint = new Point(30, 115)
  678. },
  679. new Avalonia.Controls.Shapes.Path
  680. {
  681. Fill = Brushes.Orange,
  682. Data = StreamGeometry.Parse("M 30,250 c 50,0 50,-50 c 50,0 50,50 h -50 v 50 l -50,-50 Z"),
  683. },
  684. new Polygon
  685. {
  686. Stroke = Brushes.DarkBlue,
  687. Fill = Brushes.Violet,
  688. Points = polygonPoints,
  689. StrokeThickness = 1,
  690. [Canvas.LeftProperty] = 150,
  691. [Canvas.TopProperty] = 180,
  692. },
  693. new Polyline
  694. {
  695. Stroke = Brushes.Brown,
  696. Points = polylinePoints,
  697. StrokeThickness = 5,
  698. StrokeJoin = PenLineJoin.Round,
  699. StrokeStartLineCap = PenLineCap.Triangle,
  700. StrokeEndLineCap = PenLineCap.Triangle,
  701. [Canvas.LeftProperty] = 30,
  702. [Canvas.TopProperty] = 350,
  703. },
  704. }
  705. },
  706. }
  707. }
  708. }
  709. };
  710. }
  711. private static TabItem AnimationsTab()
  712. {
  713. Border border1;
  714. Border border2;
  715. RotateTransform rotate;
  716. Button button1;
  717. var result = new TabItem
  718. {
  719. Header = "Animations",
  720. Content = new StackPanel
  721. {
  722. Orientation = Orientation.Vertical,
  723. Gap = 4,
  724. Margin = new Thickness(10),
  725. Children = new Controls
  726. {
  727. new TextBlock
  728. {
  729. Text = "Animations",
  730. FontWeight = FontWeight.Medium,
  731. FontSize = 20,
  732. Foreground = Brush.Parse("#212121"),
  733. },
  734. new TextBlock
  735. {
  736. Text = "A few animations showcased below",
  737. FontSize = 13,
  738. Foreground = Brush.Parse("#727272"),
  739. Margin = new Thickness(0, 0, 0, 10)
  740. },
  741. (button1 = new Button
  742. {
  743. Content = "Animate",
  744. Width = 120,
  745. [Grid.ColumnProperty] = 1,
  746. [Grid.RowProperty] = 1,
  747. }),
  748. new Canvas
  749. {
  750. ClipToBounds = false,
  751. Children = new Controls
  752. {
  753. (border1 = new Border
  754. {
  755. Width = 100,
  756. Height = 100,
  757. HorizontalAlignment = HorizontalAlignment.Center,
  758. VerticalAlignment = VerticalAlignment.Center,
  759. Background = Brushes.Crimson,
  760. RenderTransform = new RotateTransform(),
  761. Child = new Grid
  762. {
  763. Children = new Controls
  764. {
  765. new Ellipse()
  766. {
  767. Width = 100,
  768. Height = 100,
  769. Fill =
  770. new RadialGradientBrush()
  771. {
  772. GradientStops =
  773. {
  774. new GradientStop(Colors.Blue, 0),
  775. new GradientStop(Colors.Green, 1)
  776. },
  777. Radius = 75
  778. }
  779. },
  780. new Avalonia.Controls.Shapes.Path
  781. {
  782. Data =
  783. StreamGeometry.Parse(
  784. "F1 M 16.6309,18.6563C 17.1309,8.15625 29.8809,14.1563 29.8809,14.1563C 30.8809,11.1563 34.1308,11.4063 34.1308,11.4063C 33.5,12 34.6309,13.1563 34.6309,13.1563C 32.1309,13.1562 31.1309,14.9062 31.1309,14.9062C 41.1309,23.9062 32.6309,27.9063 32.6309,27.9062C 24.6309,24.9063 21.1309,22.1562 16.6309,18.6563 Z M 16.6309,19.9063C 21.6309,24.1563 25.1309,26.1562 31.6309,28.6562C 31.6309,28.6562 26.3809,39.1562 18.3809,36.1563C 18.3809,36.1563 18,38 16.3809,36.9063C 15,36 16.3809,34.9063 16.3809,34.9063C 16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z"),
  785. Fill =
  786. new LinearGradientBrush()
  787. {
  788. GradientStops =
  789. {
  790. new GradientStop(Colors.Green, 0),
  791. new GradientStop(Colors.LightSeaGreen, 1)
  792. }
  793. },
  794. HorizontalAlignment = HorizontalAlignment.Center,
  795. VerticalAlignment = VerticalAlignment.Center,
  796. RenderTransform = new MatrixTransform(Matrix.CreateScale(2, 2))
  797. }
  798. }
  799. },
  800. [Canvas.LeftProperty] = 100,
  801. [Canvas.TopProperty] = 100,
  802. }),
  803. (border2 = new Border
  804. {
  805. Width = 100,
  806. Height = 100,
  807. HorizontalAlignment = HorizontalAlignment.Center,
  808. VerticalAlignment = VerticalAlignment.Center,
  809. Background = Brushes.Coral,
  810. Child = new Image
  811. {
  812. Source = new Bitmap(GetImage("github_icon.png")),
  813. HorizontalAlignment = HorizontalAlignment.Center,
  814. VerticalAlignment = VerticalAlignment.Center,
  815. },
  816. RenderTransform = (rotate = new RotateTransform
  817. {
  818. PropertyTransitions = new PropertyTransitions
  819. {
  820. RotateTransform.AngleProperty.Transition(500),
  821. }
  822. }),
  823. PropertyTransitions = new PropertyTransitions
  824. {
  825. Layoutable.WidthProperty.Transition(300),
  826. Layoutable.HeightProperty.Transition(1000),
  827. },
  828. [Canvas.LeftProperty] = 400,
  829. [Canvas.TopProperty] = 100,
  830. }),
  831. }
  832. }
  833. },
  834. },
  835. };
  836. button1.Click += (s, e) =>
  837. {
  838. if (border2.Width == 100)
  839. {
  840. border2.Width = border2.Height = 400;
  841. rotate.Angle = 180;
  842. }
  843. else
  844. {
  845. border2.Width = border2.Height = 100;
  846. rotate.Angle = 0;
  847. }
  848. };
  849. var start = Animate.Stopwatch.Elapsed;
  850. var degrees = Animate.Timer
  851. .Select(x =>
  852. {
  853. var elapsed = (x - start).TotalSeconds;
  854. var cycles = elapsed / 4;
  855. var progress = cycles % 1;
  856. return 360.0 * progress;
  857. });
  858. border1.RenderTransform.Bind(
  859. RotateTransform.AngleProperty,
  860. degrees,
  861. BindingPriority.Animation);
  862. return result;
  863. }
  864. }
  865. }