DatePicker.xaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:r="clr-namespace:SKMC.UI.ValidationRules">
  4. <ResourceDictionary.MergedDictionaries>
  5. <ResourceDictionary Source="pack://application:,,,/SKMC.UI;component/Styles/Calendar.xaml"/>
  6. <!--<ResourceDictionary Source="pack://application:,,,/SKMC.UI;component/Assets/Brushes.xaml"/>-->
  7. <ResourceDictionary Source="pack://application:,,,/SKMC.UI;component/Converters/Converters.xaml"/>
  8. <ResourceDictionary Source="pack://application:,,,/SKMC.UI;component/Assets/Icons.xaml"/>
  9. </ResourceDictionary.MergedDictionaries>
  10. <!--日期选择-->
  11. <Style x:Key="DatePicker.Primary" TargetType="{x:Type DatePicker}">
  12. <Setter Property="Height" Value="30"/>
  13. <Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
  14. <Setter Property="Background" Value="#00FFFFFF" />
  15. <Setter Property="HorizontalContentAlignment" Value="Center"/>
  16. <Setter Property="VerticalContentAlignment" Value="Center"/>
  17. <Setter Property="IsDropDownOpen" Value="False"/>
  18. <Setter Property="FontSize" Value="{DynamicResource FontSize.Body}"/>
  19. <Setter Property="BorderThickness" Value="1" />
  20. <Setter Property="DatePicker.IsTodayHighlighted" Value="True" />
  21. <Setter Property="Padding" Value="2" />
  22. <Setter Property="DatePicker.SelectedDateFormat" Value="Short" />
  23. <Setter Property="BorderBrush">
  24. <Setter.Value>
  25. <LinearGradientBrush StartPoint=".5,1" EndPoint=".5,0">
  26. <GradientStop Offset="0" Color="#FFA3AEB9" />
  27. <GradientStop Offset="0.375" Color="#FF8399A9" />
  28. <GradientStop Offset="0.375" Color="#FF718597" />
  29. <GradientStop Offset="1" Color="#FF617584" />
  30. </LinearGradientBrush>
  31. </Setter.Value>
  32. </Setter>
  33. <Setter Property="Template">
  34. <Setter.Value>
  35. <ControlTemplate TargetType="{x:Type DatePicker}">
  36. <Border Name="PART_Root"
  37. BorderBrush="{TemplateBinding BorderBrush}"
  38. BorderThickness="{TemplateBinding BorderThickness}"
  39. Background="{TemplateBinding Background}"
  40. SnapsToDevicePixels="True">
  41. <Grid>
  42. <Grid.ColumnDefinitions>
  43. <ColumnDefinition Width="*"/>
  44. <ColumnDefinition Width="Auto"/>
  45. </Grid.ColumnDefinitions>
  46. <TextBox x:Name="PART_TextBox" Grid.Column="0"
  47. HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
  48. VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
  49. HorizontalAlignment="Stretch"
  50. VerticalAlignment="Center"
  51. Focusable="{TemplateBinding UIElement.Focusable}"
  52. Validation.ErrorTemplate="{x:Null}"
  53. MinWidth="100"
  54. Background="Transparent"
  55. BorderThickness="0"
  56. Foreground="{TemplateBinding Foreground}"
  57. FontSize="{TemplateBinding FontSize}"
  58. IsReadOnly="True">
  59. <TextBox.Text>
  60. <Binding Path="SelectedDate" Converter="{StaticResource DateTimeToStringConverter}" RelativeSource="{RelativeSource AncestorType={x:Type DatePicker}}">
  61. <Binding.ValidationRules>
  62. <r:DateTimeRule/>
  63. </Binding.ValidationRules>
  64. </Binding>
  65. </TextBox.Text>
  66. </TextBox>
  67. <Grid Name="PART_DisabledVisual" Column="0" ColumnSpan="2" IsHitTestVisible="False" Opacity="0">
  68. <Grid.ColumnDefinitions>
  69. <ColumnDefinition Width="*" />
  70. <ColumnDefinition Width="Auto" />
  71. </Grid.ColumnDefinitions>
  72. <Popup Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" StaysOpen="False" PlacementTarget="{Binding ElementName=PART_TextBox}" />
  73. </Grid>
  74. <Button x:Name="PART_Button"
  75. Grid.Row="0"
  76. Grid.Column="1"
  77. Margin="5">
  78. <Button.Style>
  79. <Style TargetType="{x:Type Button}">
  80. <Setter Property="Height" Value="25"/>
  81. <Setter Property="Width" Value="25"/>
  82. <Setter Property="HorizontalAlignment" Value="Center"/>
  83. <Setter Property="VerticalAlignment" Value="Center"/>
  84. <Setter Property="Focusable" Value="False"/>
  85. <Setter Property="Foreground" Value="{DynamicResource Brush.Text}"/>
  86. <Setter Property="Background" Value="Transparent"/>
  87. <Setter Property="HorizontalContentAlignment" Value="Center"/>
  88. <Setter Property="VerticalContentAlignment" Value="Center"/>
  89. <Setter Property="BorderThickness" Value="0"/>
  90. <Setter Property="Cursor" Value="Hand"/>
  91. <Setter Property="Template">
  92. <Setter.Value>
  93. <ControlTemplate TargetType="{x:Type Button}">
  94. <Border Background="{TemplateBinding Background}"
  95. BorderBrush="{TemplateBinding BorderBrush}"
  96. BorderThickness="{TemplateBinding BorderThickness}"
  97. HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
  98. VerticalAlignment="{TemplateBinding VerticalAlignment}">
  99. <Path x:Name="icon" Width="20" Height="20"
  100. Data="{StaticResource Icon.Calendar}"
  101. Stretch="Uniform"
  102. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  103. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  104. </Border>
  105. <ControlTemplate.Triggers>
  106. <Trigger Property="IsMouseOver" Value="False">
  107. <Setter TargetName="icon" Property="Fill" Value="{DynamicResource Brush.Icon}"/>
  108. </Trigger>
  109. <Trigger Property="IsMouseOver" Value="True">
  110. <Setter TargetName="icon" Property="Fill" Value="{DynamicResource Brush.IconInactive}"/>
  111. </Trigger>
  112. </ControlTemplate.Triggers>
  113. </ControlTemplate>
  114. </Setter.Value>
  115. </Setter>
  116. <Style.Triggers>
  117. <Trigger Property="IsEnabled" Value="False">
  118. <Setter Property="Background" Value="{DynamicResource Brush.SecondaryButtonDisabled}"/>
  119. </Trigger>
  120. <Trigger Property="IsPressed" Value="True">
  121. <Setter Property="Background" Value="{DynamicResource Brush.SecondaryButtonPressed}"/>
  122. </Trigger>
  123. </Style.Triggers>
  124. </Style>
  125. </Button.Style>
  126. </Button>
  127. <VisualStateManager.VisualStateGroups>
  128. <VisualStateGroup x:Name="CommonStates">
  129. <VisualState x:Name="Normal" />
  130. <VisualState x:Name="Disabled">
  131. <Storyboard>
  132. <DoubleAnimation Storyboard.TargetName="PART_DisabledVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
  133. </Storyboard>
  134. </VisualState>
  135. </VisualStateGroup>
  136. </VisualStateManager.VisualStateGroups>
  137. </Grid>
  138. </Border>
  139. <ControlTemplate.Triggers>
  140. <DataTrigger Value="false" Binding="{Binding Source={x:Static SystemParameters.HighContrast}}">
  141. <Setter TargetName="PART_TextBox" Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}" />
  142. </DataTrigger>
  143. </ControlTemplate.Triggers>
  144. </ControlTemplate>
  145. </Setter.Value>
  146. </Setter>
  147. <!-- 日历样式 -->
  148. <Setter Property="DatePicker.CalendarStyle" Value="{StaticResource Calendar.Primary}"/>
  149. </Style>
  150. </ResourceDictionary>