GalleryStyle.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Perspex;
  2. using Perspex.Controls;
  3. using Perspex.Controls.Presenters;
  4. using Perspex.Controls.Primitives;
  5. using Perspex.Controls.Templates;
  6. using Perspex.Media;
  7. using Perspex.Styling;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace TestApplication
  14. {
  15. internal class SampleTabStyle : Styles
  16. {
  17. public SampleTabStyle()
  18. {
  19. this.AddRange(new[]
  20. {
  21. new Style (s => s.Class("container").OfType<TabControl> ())
  22. {
  23. Setters = new[]
  24. {
  25. new Setter (TemplatedControl.TemplateProperty, new FuncControlTemplate<TabControl>(TabControlTemplate))
  26. }
  27. },
  28. new Style(s => s.Class("container").OfType<TabControl>().Child().Child().Child().Child().Child().OfType<TabStripItem>())
  29. {
  30. Setters = new[]
  31. {
  32. new Setter (TemplatedControl.TemplateProperty, new FuncControlTemplate<TabStripItem>(TabStripItemTemplate)),
  33. }
  34. },
  35. new Style(s => s.Name("PART_TabStrip").OfType<TabStrip>().Child().OfType<TabStripItem>())
  36. {
  37. Setters = new[]
  38. {
  39. new Setter(TemplatedControl.FontSizeProperty, 14.0),
  40. new Setter(TemplatedControl.ForegroundProperty, Brushes.White)
  41. }
  42. },
  43. new Style(s => s.Name("PART_TabStrip").OfType<TabStrip>().Child().OfType<TabStripItem>().Class(":selected"))
  44. {
  45. Setters = new[]
  46. {
  47. new Setter(TemplatedControl.ForegroundProperty, Brushes.White),
  48. new Setter(TemplatedControl.BackgroundProperty, new SolidColorBrush(Colors.White) { Opacity = 0.1 }),
  49. },
  50. },
  51. });
  52. }
  53. public static Control TabStripItemTemplate(TabStripItem control)
  54. {
  55. return new ContentPresenter
  56. {
  57. DataTemplates = new DataTemplates
  58. {
  59. new FuncDataTemplate<string>(x => new Border
  60. {
  61. [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty],
  62. Padding = new Thickness(10),
  63. Child = new TextBlock
  64. {
  65. VerticalAlignment = Perspex.Layout.VerticalAlignment.Center,
  66. Text = x
  67. }
  68. })
  69. },
  70. Name = "PART_ContentPresenter",
  71. [~ContentPresenter.ContentProperty] = control[~ContentControl.ContentProperty],
  72. };
  73. }
  74. public static Control TabControlTemplate(TabControl control)
  75. {
  76. return new Grid
  77. {
  78. ColumnDefinitions = new ColumnDefinitions
  79. {
  80. new ColumnDefinition(GridLength.Auto),
  81. new ColumnDefinition(new GridLength(1, GridUnitType.Star)),
  82. },
  83. Children = new Controls
  84. {
  85. new Border
  86. {
  87. Width = 190,
  88. Background = SolidColorBrush.Parse("#1976D2"),
  89. Child = new ScrollViewer
  90. {
  91. Content = new TabStrip
  92. {
  93. Name = "PART_TabStrip",
  94. ItemsPanel = new FuncTemplate<IPanel>(() => new StackPanel { Orientation = Orientation.Vertical, Gap = 4 }),
  95. Margin = new Thickness(0, 10, 0, 0),
  96. MemberSelector = TabControl.HeaderSelector,
  97. [!ItemsControl.ItemsProperty] = control[!ItemsControl.ItemsProperty],
  98. [!!SelectingItemsControl.SelectedItemProperty] = control[!!SelectingItemsControl.SelectedItemProperty],
  99. }
  100. }
  101. },
  102. new Carousel
  103. {
  104. Name = "PART_Content",
  105. MemberSelector = TabControl.ContentSelector,
  106. [~Carousel.TransitionProperty] = control[~TabControl.TransitionProperty],
  107. [!Carousel.ItemsProperty] = control[!ItemsControl.ItemsProperty],
  108. [!Carousel.SelectedItemProperty] = control[!SelectingItemsControl.SelectedItemProperty],
  109. [Grid.ColumnProperty] = 1,
  110. }
  111. }
  112. };
  113. }
  114. }
  115. }