DatePicker.xaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!--
  2. // (c) Copyright Microsoft Corporation.
  3. // This source is subject to the Microsoft Public License (Ms-PL).
  4. // Please see https://go.microsoft.com/fwlink/?LinkID=131993 for details.
  5. // All other rights reserved.
  6. -->
  7. <ResourceDictionary xmlns="https://github.com/avaloniaui"
  8. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  9. xmlns:sys="using:System">
  10. <Design.PreviewWith>
  11. <Border Padding="20" Height="500">
  12. <StackPanel Spacing="20" VerticalAlignment="Center">
  13. <DatePicker />
  14. <DatePicker CornerRadius="10" />
  15. <DatePicker IsEnabled="False" />
  16. <DatePicker>
  17. <DataValidationErrors.Error>
  18. <sys:Exception>
  19. <x:Arguments>
  20. <x:String>Error</x:String>
  21. </x:Arguments>
  22. </sys:Exception>
  23. </DataValidationErrors.Error>
  24. </DatePicker>
  25. </StackPanel>
  26. </Border>
  27. </Design.PreviewWith>
  28. <x:Double x:Key="DatePickerFlyoutPresenterHighlightHeight">40</x:Double>
  29. <x:Double x:Key="DatePickerFlyoutPresenterItemHeight">40</x:Double>
  30. <x:Double x:Key="DatePickerFlyoutPresenterAcceptDismissHostGridHeight">41</x:Double>
  31. <x:Double x:Key="DatePickerThemeMinWidth">296</x:Double>
  32. <x:Double x:Key="DatePickerThemeMaxWidth">456</x:Double>
  33. <Thickness x:Key="DatePickerFlyoutPresenterItemPadding">0,3,0,6</Thickness>
  34. <Thickness x:Key="DatePickerFlyoutPresenterMonthPadding">9,3,0,6</Thickness>
  35. <Thickness x:Key="DatePickerHostPadding">0,3,0,6</Thickness>
  36. <Thickness x:Key="DatePickerHostMonthPadding">9,3,0,6</Thickness>
  37. <x:Double x:Key="DatePickerSpacerThemeWidth">1</x:Double>
  38. <ControlTheme x:Key="FluentDatePickerFlyoutButton" TargetType="Button">
  39. <Setter Property="RenderTransform" Value="none" />
  40. <Setter Property="Template">
  41. <ControlTemplate>
  42. <ContentPresenter Name="PART_ContentPresenter"
  43. BorderBrush="{TemplateBinding BorderBrush}"
  44. Background="{TemplateBinding Background}"
  45. BorderThickness="{TemplateBinding BorderThickness}"
  46. Content="{TemplateBinding Content}"
  47. Foreground="{TemplateBinding Foreground}"
  48. HorizontalContentAlignment="Stretch"
  49. VerticalContentAlignment="Stretch"
  50. CornerRadius="{TemplateBinding CornerRadius}"/>
  51. </ControlTemplate>
  52. </Setter>
  53. <Style Selector="^:pressed">
  54. <Setter Property="RenderTransform" Value="scale(0.98)" />
  55. </Style>
  56. <Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
  57. <Setter Property="Background" Value="{DynamicResource DatePickerButtonBackgroundPressed}"/>
  58. <Setter Property="Foreground" Value="{DynamicResource DatePickerButtonForegroundPressed}"/>
  59. </Style>
  60. <Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
  61. <Setter Property="BorderBrush" Value="{DynamicResource DatePickerButtonBorderBrushDisabled}"/>
  62. <Setter Property="Background" Value="{DynamicResource DatePickerButtonBackgroundDisabled}"/>
  63. <Setter Property="Foreground" Value="{DynamicResource DatePickerButtonForegroundDisabled}"/>
  64. </Style>
  65. </ControlTheme>
  66. <ControlTheme x:Key="{x:Type DatePicker}" TargetType="DatePicker">
  67. <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
  68. <Setter Property="Foreground" Value="{DynamicResource DatePickerButtonForeground}" />
  69. <Setter Property="Background" Value="{DynamicResource DatePickerButtonBackground}"/>
  70. <Setter Property="BorderBrush" Value="{DynamicResource DatePickerButtonBorderBrush}"/>
  71. <Setter Property="BorderThickness" Value="1"/>
  72. <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
  73. <Setter Property="HorizontalAlignment" Value="Left" />
  74. <Setter Property="VerticalAlignment" Value="Center" />
  75. <Setter Property="Template">
  76. <ControlTemplate>
  77. <DataValidationErrors>
  78. <Grid Name="LayoutRoot" Margin="{TemplateBinding Padding}">
  79. <Button Name="PART_FlyoutButton"
  80. Theme="{StaticResource FluentDatePickerFlyoutButton}"
  81. Foreground="{TemplateBinding Foreground}"
  82. Background="{TemplateBinding Background}"
  83. BorderBrush="{TemplateBinding BorderBrush}"
  84. BorderThickness="{TemplateBinding BorderThickness}"
  85. CornerRadius="{TemplateBinding CornerRadius}"
  86. IsEnabled="{TemplateBinding IsEnabled}"
  87. MinWidth="{DynamicResource DatePickerThemeMinWidth}"
  88. MaxWidth="{DynamicResource DatePickerThemeMaxWidth}"
  89. HorizontalAlignment="Stretch"
  90. VerticalAlignment="Stretch"
  91. TemplatedControl.IsTemplateFocusTarget="True">
  92. <Grid Name="PART_ButtonContentGrid" ColumnDefinitions="78*,Auto,132*,Auto,78*">
  93. <TextBlock Name="PART_DayTextBlock" Text="day" HorizontalAlignment="Center"
  94. Padding="{DynamicResource DatePickerHostPadding}"
  95. FontFamily="{TemplateBinding FontFamily}"
  96. FontWeight="{TemplateBinding FontWeight}"
  97. FontSize="{TemplateBinding FontSize}"/>
  98. <TextBlock Name="PART_MonthTextBlock" Text="month" TextAlignment="Left"
  99. Padding="{DynamicResource DatePickerHostMonthPadding}"
  100. FontFamily="{TemplateBinding FontFamily}"
  101. FontWeight="{TemplateBinding FontWeight}"
  102. FontSize="{TemplateBinding FontSize}"/>
  103. <TextBlock Name="PART_YearTextBlock" Text="year" HorizontalAlignment="Center"
  104. Padding="{DynamicResource DatePickerHostPadding}"
  105. FontFamily="{TemplateBinding FontFamily}"
  106. FontWeight="{TemplateBinding FontWeight}"
  107. FontSize="{TemplateBinding FontSize}"/>
  108. <Rectangle x:Name="PART_FirstSpacer"
  109. Fill="{DynamicResource DatePickerSpacerFill}"
  110. HorizontalAlignment="Center"
  111. Width="1"
  112. Grid.Column="1" />
  113. <Rectangle x:Name="PART_SecondSpacer"
  114. Fill="{DynamicResource DatePickerSpacerFill}"
  115. HorizontalAlignment="Center"
  116. Width="1"
  117. Grid.Column="3" />
  118. </Grid>
  119. </Button>
  120. <Popup Name="PART_Popup" WindowManagerAddShadowHint="False"
  121. IsLightDismissEnabled="True" PlacementTarget="{TemplateBinding}"
  122. Placement="Bottom">
  123. <DatePickerPresenter Name="PART_PickerPresenter" />
  124. </Popup>
  125. </Grid>
  126. </DataValidationErrors>
  127. </ControlTemplate>
  128. </Setter>
  129. <Style Selector="^:disabled /template/ Rectangle">
  130. <Setter Property="Fill" Value="{DynamicResource DatePickerSpacerFillDisabled}"/>
  131. </Style>
  132. <!-- Changes foreground for watermark text when SelectedDate is null-->
  133. <Style Selector="^:hasnodate /template/ Button#PART_FlyoutButton TextBlock">
  134. <Setter Property="Foreground" Value="{DynamicResource TextControlPlaceholderForeground}"/>
  135. </Style>
  136. <Style Selector="^:error /template/ Button#PART_FlyoutButton">
  137. <Setter Property="BorderBrush" Value="{DynamicResource SystemControlErrorTextForegroundBrush}"/>
  138. </Style>
  139. </ControlTheme>
  140. <!--WinUI: DatePickerFlyoutPresenter-->
  141. <ControlTheme x:Key="{x:Type DatePickerPresenter}" TargetType="DatePickerPresenter">
  142. <Setter Property="Width" Value="296" />
  143. <Setter Property="MinWidth" Value="296" />
  144. <Setter Property="MaxHeight" Value="398" />
  145. <Setter Property="FontWeight" Value="Normal" />
  146. <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
  147. <Setter Property="Background" Value="{DynamicResource DatePickerFlyoutPresenterBackground}" />
  148. <Setter Property="BorderBrush" Value="{DynamicResource DatePickerFlyoutPresenterBorderBrush}" />
  149. <Setter Property="BorderThickness" Value="{DynamicResource DateTimeFlyoutBorderThickness}" />
  150. <Setter Property="CornerRadius" Value="{DynamicResource OverlayCornerRadius}" />
  151. <Setter Property="Template">
  152. <ControlTemplate>
  153. <Border Name="Background" Background="{TemplateBinding Background}"
  154. BorderBrush="{TemplateBinding BorderBrush}"
  155. BorderThickness="{TemplateBinding BorderThickness}"
  156. Padding="{DynamicResource DateTimeFlyoutBorderPadding}"
  157. MaxHeight="398" CornerRadius="{TemplateBinding CornerRadius}">
  158. <Grid Name="ContentRoot" RowDefinitions="*,Auto">
  159. <Grid Name="PART_PickerContainer">
  160. <Grid.Styles>
  161. <Style Selector="DateTimePickerPanel > ListBoxItem">
  162. <Setter Property="Theme" Value="{StaticResource FluentDateTimePickerItem}" />
  163. </Style>
  164. </Grid.Styles>
  165. <!--Column Definitions set in code, ignore here-->
  166. <Panel Name="PART_MonthHost">
  167. <ScrollViewer HorizontalScrollBarVisibility="Disabled"
  168. VerticalScrollBarVisibility="Hidden">
  169. <DateTimePickerPanel Name="PART_MonthSelector"
  170. PanelType="Month"
  171. ItemHeight="{DynamicResource DatePickerFlyoutPresenterItemHeight}"
  172. ShouldLoop="True" />
  173. </ScrollViewer>
  174. <RepeatButton Name="PART_MonthUpButton" Theme="{StaticResource FluentDateTimePickerUpButton}"/>
  175. <RepeatButton Name="PART_MonthDownButton" Theme="{StaticResource FluentDateTimePickerDownButton}"/>
  176. </Panel>
  177. <Panel Name="PART_DayHost">
  178. <ScrollViewer HorizontalScrollBarVisibility="Disabled"
  179. VerticalScrollBarVisibility="Hidden">
  180. <DateTimePickerPanel Name="PART_DaySelector"
  181. PanelType="Day"
  182. ItemHeight="{DynamicResource DatePickerFlyoutPresenterItemHeight}"
  183. ShouldLoop="True" />
  184. </ScrollViewer>
  185. <RepeatButton Name="PART_DayUpButton" Theme="{StaticResource FluentDateTimePickerUpButton}"/>
  186. <RepeatButton Name="PART_DayDownButton" Theme="{StaticResource FluentDateTimePickerDownButton}"/>
  187. </Panel>
  188. <Panel Name="PART_YearHost">
  189. <ScrollViewer HorizontalScrollBarVisibility="Disabled"
  190. VerticalScrollBarVisibility="Hidden">
  191. <DateTimePickerPanel Name="PART_YearSelector"
  192. PanelType="Year"
  193. ItemHeight="{DynamicResource DatePickerFlyoutPresenterItemHeight}"
  194. ShouldLoop="False" />
  195. </ScrollViewer>
  196. <RepeatButton Name="PART_YearUpButton" Theme="{StaticResource FluentDateTimePickerUpButton}"/>
  197. <RepeatButton Name="PART_YearDownButton" Theme="{StaticResource FluentDateTimePickerDownButton}"/>
  198. </Panel>
  199. <Rectangle Name="HighlightRect" IsHitTestVisible="False" ZIndex="-1"
  200. Fill="{DynamicResource DatePickerFlyoutPresenterHighlightFill}"
  201. Grid.Column="0" Grid.ColumnSpan="5" VerticalAlignment="Center"
  202. Height="{DynamicResource DatePickerFlyoutPresenterHighlightHeight}" />
  203. <Rectangle Name="PART_FirstSpacer"
  204. Fill="{DynamicResource DatePickerFlyoutPresenterSpacerFill}"
  205. HorizontalAlignment="Center"
  206. Width="{DynamicResource DatePickerSpacerThemeWidth}"
  207. Grid.Column="1" />
  208. <Rectangle Name="PART_SecondSpacer"
  209. Fill="{DynamicResource DatePickerFlyoutPresenterSpacerFill}"
  210. HorizontalAlignment="Center"
  211. Width="{DynamicResource DatePickerSpacerThemeWidth}"
  212. Grid.Column="3" />
  213. </Grid>
  214. <Grid Name="AcceptDismissGrid"
  215. Grid.Row="1"
  216. ColumnDefinitions="*,*">
  217. <Rectangle Height="{DynamicResource DatePickerSpacerThemeWidth}"
  218. VerticalAlignment="Top"
  219. Fill="{DynamicResource DatePickerFlyoutPresenterSpacerFill}"
  220. Grid.ColumnSpan="2"/>
  221. <Button Name="PART_AcceptButton"
  222. Grid.Column="0"
  223. Theme="{StaticResource FluentDateTimePickerButton}"
  224. Height="{DynamicResource DatePickerFlyoutPresenterAcceptDismissHostGridHeight}"
  225. HorizontalAlignment="Stretch"
  226. VerticalAlignment="Stretch">
  227. <Path Stroke="{Binding $parent[Button].Foreground}"
  228. StrokeLineCap="Round"
  229. StrokeThickness="0.75"
  230. Data="M0.5,8.5 5,13.5 15.5,3" />
  231. </Button>
  232. <Button Name="PART_DismissButton"
  233. Grid.Column="1"
  234. Theme="{StaticResource FluentDateTimePickerButton}"
  235. Height="{DynamicResource DatePickerFlyoutPresenterAcceptDismissHostGridHeight}"
  236. HorizontalAlignment="Stretch"
  237. VerticalAlignment="Stretch">
  238. <Path Stroke="{Binding $parent[Button].Foreground}"
  239. StrokeLineCap="Round"
  240. StrokeThickness="0.75"
  241. Data="M2,2 14,14 M2,14 14 2" />
  242. </Button>
  243. </Grid>
  244. </Grid>
  245. </Border>
  246. </ControlTemplate>
  247. </Setter>
  248. <Style Selector="^ /template/ Panel">
  249. <Style Selector="^:pointerover RepeatButton">
  250. <Setter Property="IsVisible" Value="True" />
  251. </Style>
  252. </Style>
  253. </ControlTheme>
  254. </ResourceDictionary>