• WPF-DatePicker样式UI及相关注意事项


    <!--#region DatePicker样式-->
        <!--时间控件查询-->
        <Style x:Key="DatePickerStyle" TargetType="{x:Type DatePicker}">
            <Setter Property="Foreground" Value="White"/>
            <Setter Property="IsTodayHighlighted" Value="True"/>
            <Setter Property="SelectedDateFormat" Value="Short"/>
            <Setter Property="Background" Value="#1c2535"/>
            <Setter Property="Padding" Value="2"/>
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint=".5,0" StartPoint=".5,1">
                        <GradientStop Color="#FFA3AEB9" Offset="0"/>
                        <GradientStop Color="#FF8399A9" Offset="0.375"/>
                        <GradientStop Color="#FF718597" Offset="0.375"/>
                        <GradientStop Color="#FF617584" Offset="1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="CalendarStyle" Value="{DynamicResource CalendarStyle_4}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DatePicker}">
                        <Border BorderBrush="#3b5a8a" CornerRadius="2" BorderThickness="0" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_DisabledVisual"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid x:Name="PART_Root" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                <Grid.Resources>
                                    <!--<SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF"/>-->
                                    <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
                                        <Grid>
                                            <Image x:Name="Img" Source="pack://application:,,,/NewCross.APMP.Branch.MainFramework;component/Resources/Duty/日历.png"/>
                                        </Grid>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter TargetName="Img" Property="Source" Value="pack://application:,,,/NewCross.APMP.Branch.MainFramework;component/Resources/Duty/日历_选中.png"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Grid.Resources>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Button x:Name="PART_Button" Grid.Column="1" Foreground="{TemplateBinding Foreground}" Focusable="False" HorizontalAlignment="Left" Margin="3,0,3,0" Grid.Row="0" Template="{StaticResource DropDownButtonTemplate}" VerticalAlignment="Top" Width="20"/>
                                <DatePickerTextBox x:Name="PART_TextBox" Foreground="White" Background="#202d44" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="Stretch" Grid.Row="0" VerticalContentAlignment="Stretch" Style="{DynamicResource DatePickerTextBoxStyle}"/>
                                <Grid x:Name="PART_DisabledVisual" Grid.ColumnSpan="2" Grid.Column="0" IsHitTestVisible="False" Opacity="0" Grid.Row="0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Rectangle Grid.Column="0" Fill="#A5FFFFFF" RadiusY="1" Grid.Row="0" RadiusX="1"/>
                                    <Rectangle Grid.Column="1" Fill="#A5FFFFFF" Height="18" Margin="3,0,3,0" RadiusY="1" Grid.Row="0" RadiusX="1" Width="19"/>
                                    <Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>
                                </Grid>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="false">
                                <Setter Property="Foreground" TargetName="PART_TextBox" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"/>
                            </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="DatePickerTextBoxStyle" TargetType="{x:Type DatePickerTextBox}">
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
            <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DatePickerTextBox}">
                        <Grid>
                            <Grid.Resources>
                                <SolidColorBrush x:Key="WatermarkBrush" Color="#FFAAAAAA"/>
                            </Grid.Resources>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition GeneratedDuration="0"/>
                                        <VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/>
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ColorAnimation Duration="0" To="#FF99C1E2" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" Storyboard.TargetName="ContentElement"/>
                                            <ColorAnimation Duration="0" To="#FF99C1E2" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" Storyboard.TargetName="watermark_decorator"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="WatermarkStates">
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition GeneratedDuration="0"/>
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Unwatermarked"/>
                                    <VisualState x:Name="Watermarked">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentElement"/>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Watermark"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition GeneratedDuration="0"/>
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Unfocused"/>
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisual"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0" Background="#202d44" CornerRadius="1" Opacity="1" Padding="3,2,0,0">
                                <Grid x:Name="WatermarkContent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                    <Border x:Name="ContentElement" BorderBrush="#FFFFFFFF" BorderThickness="0"/>
                                    <Border x:Name="watermark_decorator" BorderBrush="#FFFFFFFF" BorderThickness="0">
                                        <ContentControl x:Name="PART_Watermark" Focusable="False" IsHitTestVisible="False" Opacity="0" Padding="2"/>
                                    </Border>
                                    <ScrollViewer x:Name="PART_ContentHost" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                    <Border x:Name="FocusVisual" BorderBrush="#FF45D6FA" CornerRadius="1" IsHitTestVisible="False" Opacity="0"/>
                                </Grid>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
        <Style x:Key="DatePickerStyle2" TargetType="{x:Type DatePicker}">
            <Setter Property="Foreground" Value="#FF333333"/>
            <Setter Property="IsTodayHighlighted" Value="True"/>
            <Setter Property="SelectedDateFormat" Value="Short"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Padding" Value="2"/>
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint=".5,0" StartPoint=".5,1">
                        <GradientStop Color="#FFA3AEB9" Offset="0"/>
                        <GradientStop Color="#FF8399A9" Offset="0.375"/>
                        <GradientStop Color="#FF718597" Offset="0.375"/>
                        <GradientStop Color="#FF617584" Offset="1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="CalendarStyle" Value="{DynamicResource CalendarStyle_4}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DatePicker}">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_DisabledVisual"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid x:Name="PART_Root" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                <Grid.Resources>
                                    <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF"/>
                                    <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
                                        <Grid>
                                            <Grid>
                                                <Image x:Name="Img" Height="22" Width="22" Source="pack://application:,,,/NewCross.APMP.Branch.MainFramework;component/Resources/Duty/日历.png"/>
                                            </Grid>
                                        </Grid>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter TargetName="Img" Property="Source" Value="pack://application:,,,/NewCross.APMP.Branch.MainFramework;component/Resources/Duty/日历_选中.png"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Grid.Resources>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Button x:Name="PART_Button" Grid.Column="1" Foreground="{TemplateBinding Foreground}" Focusable="False" HorizontalAlignment="Left" Margin="1,0,3,0" Grid.Row="0" Template="{StaticResource DropDownButtonTemplate}" VerticalAlignment="Top" Width="23"/>
                                <DatePickerTextBox x:Name="PART_TextBox"  Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="Stretch" Grid.Row="0" VerticalContentAlignment="Stretch"/>
                                <Grid x:Name="PART_DisabledVisual" Grid.ColumnSpan="2" Grid.Column="0" IsHitTestVisible="False" Opacity="0" Grid.Row="0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Rectangle Grid.Column="0" Fill="#A5FFFFFF" RadiusY="1" Grid.Row="0" RadiusX="1"/>
                                    <Rectangle Grid.Column="1" Fill="#A5FFFFFF" Height="22" Width="22" Margin="0,0,0,0" RadiusY="1" Grid.Row="0" RadiusX="1"/>
                                    <Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>
                                </Grid>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="false">
                                <Setter Property="Foreground" TargetName="PART_TextBox" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"/>
                            </DataTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <!--#endregion DatePicker样式-->

    ===============

      1 <!--Region  Datepicker、Calendar样式4-->
      2     <Style x:Key="DatePickerStyle_4" TargetType="{x:Type DatePicker}">
      3         <Setter Property="Foreground" Value="White"/>
      4         <Setter Property="IsTodayHighlighted" Value="True"/>
      5         <Setter Property="SelectedDateFormat" Value="Short"/>
      6         <Setter Property="Background" Value="#202d44"/>
      7         <Setter Property="Padding" Value="2"/>
      8         <Setter Property="BorderBrush">
      9             <Setter.Value>
     10                 <LinearGradientBrush EndPoint=".5,0" StartPoint=".5,1">
     11                     <GradientStop Color="#FFA3AEB9" Offset="0"/>
     12                     <GradientStop Color="#FF8399A9" Offset="0.375"/>
     13                     <GradientStop Color="#FF718597" Offset="0.375"/>
     14                     <GradientStop Color="#FF617584" Offset="1"/>
     15                 </LinearGradientBrush>
     16             </Setter.Value>
     17         </Setter>
     18         <Setter Property="BorderThickness" Value="0"/>
     19         <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
     20         <Setter Property="Template">
     21             <Setter.Value>
     22                 <ControlTemplate TargetType="{x:Type DatePicker}">
     23                     <Border BorderBrush="#3b5a8a" CornerRadius="2" BorderThickness="0" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" 
     24                             >
     25                         <VisualStateManager.VisualStateGroups>
     26                             <VisualStateGroup x:Name="CommonStates">
     27                                 <VisualState x:Name="Normal"/>
     28                                 <VisualState x:Name="Disabled">
     29                                     <Storyboard>
     30                                         <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_DisabledVisual"/>
     31                                     </Storyboard>
     32                                 </VisualState>
     33                             </VisualStateGroup>
     34                         </VisualStateManager.VisualStateGroups>
     35                         <Grid x:Name="PART_Root" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
     36                             <Grid.Resources>
     37                                 <!--<SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF"/>-->
     38                                 <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
     39                                     <Grid>
     40                                         <Image x:Name="Img" Source="pack://application:,,,/NewCross.APMP.Branch.MainFramework;component/Resources/Duty/日历.png"/>
     41                                     </Grid>
     42                                     <ControlTemplate.Triggers>
     43                                         <Trigger Property="IsMouseOver" Value="True">
     44                                             <Setter TargetName="Img" Property="Source" Value="pack://application:,,,/NewCross.APMP.Branch.MainFramework;component/Resources/Duty/日历_选中.png"/>
     45                                         </Trigger>
     46                                     </ControlTemplate.Triggers>
     47                                 </ControlTemplate>
     48                             </Grid.Resources>
     49                             <Grid.ColumnDefinitions>
     50                                 <ColumnDefinition Width="*"/>
     51                                 <ColumnDefinition Width="Auto"/>
     52                             </Grid.ColumnDefinitions>
     53                             <Button x:Name="PART_Button" Grid.Column="1" Foreground="{TemplateBinding Foreground}" Focusable="False" HorizontalAlignment="Left" Margin="3,0,3,0" Grid.Row="0" Template="{StaticResource DropDownButtonTemplate}" VerticalAlignment="Top" Width="20"/>
     54                             <DatePickerTextBox x:Name="PART_TextBox" Foreground="White" Background="#202d44" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="Stretch" Grid.Row="0" VerticalContentAlignment="Stretch" Style="{DynamicResource DatePickerTextBoxStyle}"/>
     55                             <Grid x:Name="PART_DisabledVisual" Grid.ColumnSpan="2" Grid.Column="0" IsHitTestVisible="False" Opacity="0" Grid.Row="0">
     56                                 <Grid.ColumnDefinitions>
     57                                     <ColumnDefinition Width="*"/>
     58                                     <ColumnDefinition Width="Auto"/>
     59                                 </Grid.ColumnDefinitions>
     60                                 <Rectangle Grid.Column="0" Fill="#A5FFFFFF" RadiusY="1" Grid.Row="0" RadiusX="1"/>
     61                                 <Rectangle Grid.Column="1" Fill="#A5FFFFFF" Height="18" Margin="3,0,3,0" RadiusY="1" Grid.Row="0" RadiusX="1" Width="19"/>
     62                                 <Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>
     63                             </Grid>
     64                         </Grid>
     65                     </Border>
     66                     <ControlTemplate.Triggers>
     67                         <DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="false">
     68                             <Setter Property="Foreground" TargetName="PART_TextBox" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"/>
     69                         </DataTrigger>
     70                     </ControlTemplate.Triggers>
     71                 </ControlTemplate>
     72             </Setter.Value>
     73         </Setter>
     74         <Setter Property="CalendarStyle" Value="{DynamicResource CalendarStyle_4}">
     75             <!--<Setter.Value>
     76                 <Style TargetType="{x:Type Calendar}">
     77                     <Setter Property="SnapsToDevicePixels" Value="True" />
     78                     <Setter Property="Foreground" Value="Red" />
     79                     <Setter Property="CalendarDayButtonStyle" Value="{DynamicResource CalendarDayButtonStyle_4}" />
     80                     <Setter Property="CalendarItemStyle" Value="{DynamicResource CalendarItemStyle_4}" />
     81                     <Setter Property="CalendarButtonStyle" Value="{DynamicResource CalendarButtonStyle_4}" />
     82                     <Setter Property="Background" Value="Transparent" />
     83                     <Setter Property="BorderBrush" Value="Transparent" />
     84                     <Setter Property="BorderThickness" Value="1" />
     85                     <Setter Property="FontSize" Value="5" /> 
     86                     <Setter Property="IsTodayHighlighted" Value="True" />
     87                     <Setter Property="Template">
     88                         <Setter.Value>
     89                             <ControlTemplate TargetType="{x:Type Calendar}">
     90                                 <StackPanel x:Name="PART_Root" HorizontalAlignment="Center" Background="Transparent">
     91                                     <CalendarItem x:Name="PART_CalendarItem" BorderBrush="{TemplateBinding BorderBrush}" FontSize="{TemplateBinding FontSize}"
     92                                       FontFamily="{TemplateBinding FontFamily}"
     93                                       BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
     94                                       Style="{TemplateBinding CalendarItemStyle}" />
     95                                 </StackPanel>
     96                             </ControlTemplate>
     97                         </Setter.Value>
     98                     </Setter>
     99                 </Style>
    100             </Setter.Value>-->
    101         </Setter>
    102     </Style>
    103     <!--Day按钮样式-->
    104     <Style x:Key="CalendarDayButtonStyle_4" TargetType="{x:Type CalendarDayButton}">
    105         <!--<Setter Property="MinWidth" Value="28" />
    106         <Setter Property="MinHeight" Value="5" />-->
    107         <!--<Setter Property="FontFamily" Value="{StaticResource FontFamily}" />-->
    108         <Setter Property="HorizontalContentAlignment" Value="Center" />
    109         <Setter Property="VerticalContentAlignment" Value="Center" />
    110         <Setter Property="Background" Value="Transparent" />
    111         <Setter Property="Foreground" Value="White" />
    112         <Setter Property="Margin" Value="0" />
    113         <Setter Property="IsTabStop" Value="False" />
    114         <Setter Property="Template">
    115             <Setter.Value>
    116                 <ControlTemplate TargetType="{x:Type CalendarDayButton}">
    117                     <Grid x:Name="Grid" Margin="{TemplateBinding Margin}">
    118                         <Border x:Name="Bg"  Background="{TemplateBinding Background}" />
    119 
    120                         <ContentPresenter x:Name="NormalText" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="5,2,5,2" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
    121                                           TextElement.Foreground="{TemplateBinding Foreground}" />
    122                     </Grid>
    123                     <ControlTemplate.Triggers>
    124                         <Trigger Property="IsSelected" Value="True">
    125                             <!--<Setter TargetName="Bg" Property="CornerRadius" Value="6"></Setter>-->
    126                             <Setter Property="Background" Value="White"></Setter>
    127                             <Setter Property="Foreground" Value="#016B77"></Setter>
    128                         </Trigger>
    129                         <Trigger Property="IsToday" Value="True">
    130                             <!--<Setter TargetName="Bg" Property="CornerRadius" Value="6"></Setter>-->
    131                             <Setter Property="Background" Value="#016B77"></Setter>
    132                             <Setter Property="Foreground" Value="White"></Setter>
    133                         </Trigger>
    134                         <Trigger Property="IsMouseOver" Value="True">
    135                             <!--<Setter TargetName="Bg" Property="CornerRadius" Value="6"></Setter>-->
    136                             <!--<Setter TargetName="Bg" Property="BorderThickness" Value="0.5"></Setter>-->
    137                             <!--<Setter TargetName="Bg" Property="BorderBrush" Value="Yellow"></Setter>-->
    138                             <Setter Property="Background" Value="LightBlue"></Setter>
    139                             <!--<Setter Property="Foreground" Value="Green"></Setter>-->
    140                         </Trigger>
    141                         <!--不可用日期-->
    142                         <Trigger Property="IsBlackedOut" Value="True">
    143                             <Setter Property="Opacity" Value="0.5" TargetName="Grid"></Setter>
    144                         </Trigger>
    145                         <!--不在当月的日期-->
    146                         <Trigger Property="IsInactive" Value="True">
    147                             <Setter Property="Opacity" Value="0.5" TargetName="Grid"></Setter>
    148                         </Trigger>
    149                         <Trigger Property="IsEnabled" Value="False">
    150                             <Setter Property="Opacity" Value="0.8" TargetName="Grid"></Setter>
    151                         </Trigger>
    152                     </ControlTemplate.Triggers>
    153                 </ControlTemplate>
    154             </Setter.Value>
    155         </Setter>
    156     </Style>
    157     <!--日历日期面板样式-->
    158     <Style x:Key="CalendarItemStyle_4" TargetType="{x:Type CalendarItem}">
    159         <Setter Property="Margin" Value="0,1,0,1" />
    160         <Setter Property="Background" Value="#016B77"/>
    161         <Setter Property="Template">
    162             <Setter.Value>
    163                 <ControlTemplate TargetType="{x:Type CalendarItem}">
    164                     <ControlTemplate.Resources>
    165                         <!-- 头部星期样式-->
    166                         <DataTemplate x:Key="{x:Static CalendarItem.DayTitleTemplateResourceKey}">
    167                             <TextBlock Text="{Binding}" FontSize="10" FontWeight="Bold" Margin="6,5,0,3" Opacity="0.8" Foreground="White"/>
    168                         </DataTemplate>
    169                     </ControlTemplate.Resources>
    170                     <Grid x:Name="PART_Root">
    171                         <Grid.Resources>
    172                             <!--设置日历控件 IsEnable=false 时的不可用遮罩层颜色,并且会播放过渡动画-->
    173                             <SolidColorBrush x:Key="DisabledColor" Color="#A5FFFFFF" />
    174                         </Grid.Resources>
    175                         <VisualStateManager.VisualStateGroups>
    176                             <VisualStateGroup x:Name="CommonStates">
    177                                 <VisualState x:Name="Normal" />
    178                                 <VisualState x:Name="Disabled">
    179                                     <!--设置日历控件 IsEnable=false 时遮罩层透明度0-1变色动画-->
    180                                     <Storyboard>
    181                                         <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_DisabledVisual" />
    182                                     </Storyboard>
    183                                 </VisualState>
    184                             </VisualStateGroup>
    185                         </VisualStateManager.VisualStateGroups>
    186 
    187                         <Border BorderBrush="#cfcfcf" BorderThickness="0" Background="{TemplateBinding Background}" CornerRadius="2">
    188                             <Grid>
    189                                 <Grid.Resources>
    190                                     <!--日历头左箭头按钮样式模版-->
    191                                     <ControlTemplate x:Key="PreviousButtonTemplate" TargetType="{x:Type Button}">
    192                                         <!--鼠标悬停在左箭头按钮上时改变鼠标指针样式-->
    193                                         <Grid Cursor="Hand">
    194                                             <VisualStateManager.VisualStateGroups>
    195                                                 <VisualStateGroup x:Name="CommonStates">
    196                                                     <VisualState x:Name="Normal" />
    197                                                     <VisualState x:Name="MouseOver">
    198                                                         <!--鼠标悬停在左箭头按钮上时左箭头颜色变化动画-->
    199                                                         <Storyboard>
    200                                                             <ColorAnimation Duration="0" To="#FF73A9D8" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="path" />
    201                                                         </Storyboard>
    202                                                     </VisualState>
    203                                                     <VisualState x:Name="Disabled">
    204                                                         <Storyboard>
    205                                                             <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="(Shape.Fill).(Brush.Opacity)"  Storyboard.TargetName="path" />
    206                                                         </Storyboard>
    207                                                     </VisualState>
    208                                                 </VisualStateGroup>
    209                                             </VisualStateManager.VisualStateGroups>
    210                                             <!--左箭头整个区域矩形块-->
    211                                             <Rectangle Fill="#016B77" Opacity="1" Stretch="Fill" />
    212                                             <Grid>
    213                                                 <!--左箭头-->
    214                                                 <Path x:Name="path"  Data="M288.75,232.25 L288.75,240.625 L283,236.625 z"  Fill="#e0e0e0" HorizontalAlignment="Left"
    215                                                               Height="8"  Width="8"  Margin="10,2,0,0"  Stretch="Fill" VerticalAlignment="Center" />
    216                                             </Grid>
    217                                         </Grid>
    218                                     </ControlTemplate>
    219                                     <!--日历头右箭头按钮样式模版,这块跟左箭头样式模版没什么区别-->
    220                                     <ControlTemplate x:Key="NextButtonTemplate" TargetType="{x:Type Button}">
    221                                         <Grid Cursor="Hand">
    222                                             <VisualStateManager.VisualStateGroups>
    223                                                 <VisualStateGroup x:Name="CommonStates">
    224                                                     <VisualState x:Name="Normal" />
    225                                                     <VisualState x:Name="MouseOver">
    226                                                         <Storyboard>
    227                                                             <ColorAnimation Duration="0" To="#FF73A9D8" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"  Storyboard.TargetName="path" />
    228                                                         </Storyboard>
    229                                                     </VisualState>
    230                                                     <VisualState x:Name="Disabled">
    231                                                         <Storyboard>
    232                                                             <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="(Shape.Fill).(Brush.Opacity)" Storyboard.TargetName="path" />
    233                                                         </Storyboard>
    234                                                     </VisualState>
    235                                                 </VisualStateGroup>
    236                                             </VisualStateManager.VisualStateGroups>
    237                                             <Rectangle Fill="#016B77" Opacity="1" Stretch="Fill" />
    238                                             <Grid>
    239                                                 <Path x:Name="path" Data="M282.875,231.875 L282.875,240.375 L288.625,236 z" Fill="#e0e0e0" HorizontalAlignment="Right"
    240                                                               Height="8" Width="8" Margin="0,2,10,0" Stretch="Fill" VerticalAlignment="Center" />
    241                                             </Grid>
    242                                         </Grid>
    243                                     </ControlTemplate>
    244                                     <!--日历头中间年按钮样式模版-->
    245                                     <ControlTemplate x:Key="HeaderButtonTemplate" TargetType="{x:Type Button}">
    246                                         <Grid Cursor="Hand">
    247                                             <VisualStateManager.VisualStateGroups>
    248                                                 <VisualStateGroup x:Name="CommonStates">
    249                                                     <VisualState x:Name="Normal" />
    250                                                     <VisualState x:Name="MouseOver">
    251                                                         <Storyboard>
    252                                                             <ColorAnimation Duration="0" To="#FF73A9D8" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="buttonContent" />
    253                                                         </Storyboard>
    254                                                     </VisualState>
    255                                                     <VisualState x:Name="Disabled">
    256                                                         <Storyboard>
    257                                                             <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="buttonContent" />
    258                                                         </Storyboard>
    259                                                     </VisualState>
    260                                                 </VisualStateGroup>
    261                                             </VisualStateManager.VisualStateGroups>
    262                                             <ContentPresenter x:Name="buttonContent" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" TextElement.Foreground="#e0e0e0"
    263                                                                       HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1,3,1,1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
    264                                         </Grid>
    265                                     </ControlTemplate>
    266                                 </Grid.Resources>
    267 
    268                                 <Grid.RowDefinitions>
    269                                     <!--日历头,左箭头,年,右箭头-->
    270                                     <RowDefinition Height="Auto" />
    271                                     <!--日历内容,星期几和具体的日期几号几号-->
    272                                     <RowDefinition Height="*" />
    273                                 </Grid.RowDefinitions>
    274                                 <Grid.ColumnDefinitions>
    275                                     <!--左箭头-->
    276                                     <ColumnDefinition Width="Auto" />
    277                                     <!---->
    278                                     <ColumnDefinition Width="*" />
    279                                     <!--右箭头-->
    280                                     <ColumnDefinition Width="Auto" />
    281                                 </Grid.ColumnDefinitions>
    282                                 <!--头,左箭头,年,右箭头,整体的背景色-->
    283                                 <Border Grid.Row="0" Grid.ColumnSpan="3" Background="#016B77"></Border>
    284                                 <!--左箭头-->
    285                                 <Button x:Name="PART_PreviousButton" Grid.Column="0" Focusable="False" HorizontalAlignment="Left" Grid.Row="0"
    286                                                 Template="{StaticResource PreviousButtonTemplate}" />
    287                                 <!---->
    288                                 <Button x:Name="PART_HeaderButton" Grid.Column="1" FontFamily="微软雅黑" Focusable="False" FontSize="12"
    289                                                 HorizontalAlignment="Center"  Grid.Row="0" Template="{StaticResource HeaderButtonTemplate}" VerticalAlignment="Center" />
    290                                 <!--右箭头-->
    291                                 <Button x:Name="PART_NextButton"  Grid.Column="2"  Focusable="False"
    292                                                 HorizontalAlignment="Right" Grid.Row="0" Template="{StaticResource NextButtonTemplate}" />
    293                                 <!--日期几号几号内容显示-->
    294                                 <Border Grid.Row="1" Grid.ColumnSpan="3" Margin="0" BorderBrush="Transparent" BorderThickness="0" Background="Transparent">
    295                                     <Grid x:Name="PART_MonthView" HorizontalAlignment="Center" Visibility="Visible">
    296                                         <Grid.ColumnDefinitions>
    297                                             <ColumnDefinition Width="*" />
    298                                             <ColumnDefinition Width="*" />
    299                                             <ColumnDefinition Width="*" />
    300                                             <ColumnDefinition Width="*" />
    301                                             <ColumnDefinition Width="*" />
    302                                             <ColumnDefinition Width="*" />
    303                                             <ColumnDefinition Width="*" />
    304                                         </Grid.ColumnDefinitions>
    305                                         <Grid.RowDefinitions>
    306                                             <RowDefinition Height="auto" />
    307                                             <RowDefinition Height="*" />
    308                                             <RowDefinition Height="*" />
    309                                             <RowDefinition Height="*" />
    310                                             <RowDefinition Height="*" />
    311                                             <RowDefinition Height="*" />
    312                                             <RowDefinition Height="*" />
    313                                         </Grid.RowDefinitions>
    314                                     </Grid>
    315                                 </Border>
    316 
    317                                 <!--月和年内容显示-->
    318                                 <Grid x:Name="PART_YearView" Grid.ColumnSpan="3"  HorizontalAlignment="Center" Grid.Row="1" Visibility="Hidden" VerticalAlignment="Center">
    319                                     <Grid.ColumnDefinitions>
    320                                         <ColumnDefinition Width="*" />
    321                                         <ColumnDefinition Width="*" />
    322                                         <ColumnDefinition Width="*" />
    323                                         <ColumnDefinition Width="*" />
    324                                     </Grid.ColumnDefinitions>
    325                                     <Grid.RowDefinitions>
    326                                         <RowDefinition Height="*" />
    327                                         <RowDefinition Height="*" />
    328                                         <RowDefinition Height="*" />
    329                                     </Grid.RowDefinitions>
    330                                 </Grid>
    331                             </Grid>
    332                         </Border>
    333                         <!--日历不可用的遮罩层-->
    334                         <Rectangle x:Name="PART_DisabledVisual"  Fill="{StaticResource DisabledColor}" Opacity="0" RadiusY="2" RadiusX="2" Stretch="Fill"
    335                                        Stroke="{StaticResource DisabledColor}" StrokeThickness="1" Visibility="Collapsed" />
    336                     </Grid>
    337                     <ControlTemplate.Triggers>
    338                         <Trigger Property="IsEnabled" Value="False">
    339                             <Setter Property="Opacity" TargetName="PART_Root" Value="0.65" />
    340                         </Trigger>
    341                         <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Year">
    342                             <Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden" />
    343                             <Setter Property="Visibility" TargetName="PART_YearView" Value="Visible" />
    344                         </DataTrigger>
    345                         <!--Decade 美 ['dɛked] n. 十年,十年期;十-->
    346                         <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Decade">
    347                             <Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden" />
    348                             <Setter Property="Visibility" TargetName="PART_YearView" Value="Visible" />
    349                         </DataTrigger>
    350                     </ControlTemplate.Triggers>
    351                 </ControlTemplate>
    352             </Setter.Value>
    353         </Setter>
    354     </Style>
    355     <!--年、月按钮样式-->
    356     <Style x:Key="CalendarButtonStyle_4" TargetType="{x:Type CalendarButton}">
    357         <Setter Property="Background" Value="Transparent" />
    358         <Setter Property="HorizontalContentAlignment" Value="Center" />
    359         <Setter Property="VerticalContentAlignment" Value="Center" />
    360         <Setter Property="Template">
    361             <Setter.Value>
    362                 <ControlTemplate TargetType="{x:Type CalendarButton}">
    363                     <Grid x:Name="Grid" Margin="{TemplateBinding Margin}">
    364                         <Border x:Name="Bg" Background="{TemplateBinding Background}" />
    365                         <ContentPresenter x:Name="NormalText" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
    366                                           Margin="5,2,5,2" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
    367                                           TextElement.Foreground="{TemplateBinding Foreground}" />
    368                     </Grid>
    369                     <ControlTemplate.Triggers>
    370                         <Trigger Property="IsFocused" Value="True">
    371                             <Setter Property="Background" Value="#016B77" ></Setter>
    372                             <Setter Property="Foreground" Value="White"></Setter>
    373                         </Trigger>
    374                         <Trigger Property="IsMouseOver" Value="True">
    375                             <Setter Property="Background" Value="LightBlue" ></Setter>
    376                             <!--<Setter Property="Foreground" Value="White"></Setter>-->
    377                         </Trigger>
    378                         <!--不在当月的日期-->
    379                         <Trigger Property="IsInactive" Value="True">
    380                             <Setter Property="Opacity" Value="0.5" TargetName="Grid"></Setter>
    381                         </Trigger>
    382                         <Trigger Property="IsEnabled" Value="False">
    383                             <Setter Property="Opacity" Value="0.8" TargetName="Grid"></Setter>
    384                         </Trigger>
    385                     </ControlTemplate.Triggers>
    386                 </ControlTemplate>
    387             </Setter.Value>
    388         </Setter>
    389     </Style>
    390     <ImageBrush x:Key="bg_Calendar" ImageSource="pack://application:,,,/NewCross.APMP.Branch.MainFramework;component/Resources/Duty/日历背景.png" Stretch="Fill"/>
    391     <Style x:Key="CalendarStyle_4" TargetType="Calendar">
    392         <Setter Property="SnapsToDevicePixels" Value="True" />
    393         <Setter Property="Foreground" Value="White" />
    394         <Setter Property="CalendarDayButtonStyle" Value="{DynamicResource CalendarDayButtonStyle_4}" />
    395         <Setter Property="CalendarItemStyle" Value="{DynamicResource CalendarItemStyle_4}" />
    396         <Setter Property="CalendarButtonStyle" Value="{DynamicResource CalendarButtonStyle_4}" />
    397         <!--<Setter Property="Background" Value="#1AAEB7" />-->
    398         <Setter Property="Background" Value="{DynamicResource bg_Calendar}" />
    399         <Setter Property="BorderBrush" Value="#35405a" />
    400         <Setter Property="BorderThickness" Value="0" />
    401         <Setter Property="FontSize" Value="10" />
    402         <Setter Property="IsTodayHighlighted" Value="True" />
    403         <Setter Property="Template">
    404             <Setter.Value>
    405                 <ControlTemplate TargetType="{x:Type Calendar}">
    406                     <StackPanel x:Name="PART_Root" HorizontalAlignment="Center" Background="Transparent">
    407                         <CalendarItem x:Name="PART_CalendarItem" BorderBrush="{TemplateBinding BorderBrush}" FontSize="{TemplateBinding FontSize}" Foreground="{TemplateBinding Foreground}"
    408                             BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
    409                            Style="{TemplateBinding CalendarItemStyle}" >
    410                         </CalendarItem>
    411                     </StackPanel>
    412                 </ControlTemplate>
    413             </Setter.Value>
    414         </Setter>
    415     </Style>
    416     <!--EndRegion  Datepicker、Calendar样式4-->
    View Code

    ===============相关注意事项===============

    =====1、上述样式来源http://www.cnblogs.com/anding

    =====2、如果需要对日期等格式化,请参考以下对“DatePickerTextBox”样式的调整。因为默认的样式会受到系统日期格式的影响

     1 <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0" Background="#162133" CornerRadius="1" Opacity="1" Padding="{TemplateBinding Padding}">
     2                                     <Grid x:Name="WatermarkContent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
     3                                         <Border x:Name="ContentElement" BorderBrush="#FFFFFFFF" BorderThickness="0"/>
     4                                         <Border x:Name="watermark_decorator" BorderBrush="#FFFFFFFF" BorderThickness="0">
     5                                             <!--<ContentControl x:Name="PART_Watermark" Focusable="False" IsHitTestVisible="False" Opacity="0" Padding="2"/>-->
     6                                             <TextBox x:Name="PART_Watermark" Text="{Binding Path=SelectedDate, StringFormat='yyyy/MM/dd', RelativeSource={RelativeSource AncestorType=DatePicker}}" Background="Transparent" Foreground="White" BorderThickness="0"/>
     7                                         </Border>
     8                                         <!--使用ScrollViewer 会出现默认系统日期格式-->
     9                                         <!--<ScrollViewer x:Name="PART_ContentHost" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>-->
    10                                         <Border x:Name="FocusVisual" BorderBrush="#FF45D6FA" CornerRadius="1" IsHitTestVisible="False" Opacity="0"/>
    11                                     </Grid>
    12                                 </Border>
    View Code
  • 相关阅读:
    C#中的赋值运算符及其运算规则
    值类型与引用类型
    变量的作用域和生存周期
    Eclipse 和 Vim 协同使用使用Eclim插件开发Python程序
    使用合适的设计模式一步步优化前端代码
    Vue.js 服务端渲染业务入门实践
    翻译连载 | 第 9 章:递归(下)-《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇
    翻译连载 |《你不知道的JS》姊妹篇 |《JavaScript 轻量级函数式编程》 第 7 章: 闭包 vs 对象
    翻译连载 | 第 10 章:异步的函数式(下)-《JavaScript轻量级函数式编程》 |《你不知道的JS》姊妹篇
    微信小程序教学第四章第二节(含视频):小程序中级实战教程:详情视图渲染
  • 原文地址:https://www.cnblogs.com/xbj-hyml/p/10653618.html
Copyright © 2020-2023  润新知