WPF DatePicker自定义样式

8 篇文章 1 订阅

效果图:

  

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:system="clr-namespace:System;assembly=mscorlib">
        <!--Window窗体-->
        <SolidColorBrush x:Key="WindowBackground" Color="#007ACB"></SolidColorBrush>
        <SolidColorBrush x:Key="WindowInnerBackground" Color="Transparent"></SolidColorBrush>
        <SolidColorBrush x:Key="WindowBorderBrush" Color="#920892"></SolidColorBrush>
        <DropShadowEffect x:Key="WindowDropShadow" Color="Red" BlurRadius="8" ShadowDepth="0" Direction="0" Opacity="0.7" />
        <SolidColorBrush x:Key="CaptionForeground" Color="White"></SolidColorBrush>
        <LinearGradientBrush x:Key="CaptionBackground" StartPoint="0.5,0" EndPoint="0.5,1">
            <GradientStop Color="#571457" Offset="0"/>
            <GradientStop Color="#6A196A" Offset="1"/>
        </LinearGradientBrush>
        <!--MessageBoxX-->
        <SolidColorBrush x:Key="InfoForeground" Color="White"></SolidColorBrush>
        <SolidColorBrush x:Key="QuestionForeground" Color="#74B80C"></SolidColorBrush>
        <SolidColorBrush x:Key="WarningForeground" Color="DarkOrange"></SolidColorBrush>
        <SolidColorBrush x:Key="ErrorForeground" Color="#E74E4E"></SolidColorBrush>
        <!--WaitingBox-->
        <SolidColorBrush x:Key="WaitingBoxBackground" Color="#921692"></SolidColorBrush>
        <!--边框:Menu-->
        <DropShadowEffect x:Key="DefaultDropShadow" Color="Black" BlurRadius="5" ShadowDepth="2" Direction="315" Opacity="0.6" />
        <!--输入组件-->
        <SolidColorBrush x:Key="TextForeground" Color="Black"></SolidColorBrush>
        <SolidColorBrush x:Key="TextBackground" Color="White"></SolidColorBrush>
        <SolidColorBrush x:Key="TextSelectionBrush" Color="#8F8787"></SolidColorBrush>
        <!--TextBox默认Label颜色-->
        <SolidColorBrush x:Key="TextLabelBackground" Color="#508AB6"></SolidColorBrush>
        <!--输入框-->
        <SolidColorBrush x:Key="ControlBorderBrush" Color="#999C9F"></SolidColorBrush>
        <SolidColorBrush x:Key="MouseOverBorderBrush" Color="#F6D1D1"></SolidColorBrush>
        <SolidColorBrush x:Key="FocusBackground" Color="#365080"></SolidColorBrush>
        <SolidColorBrush x:Key="FocusBorderBrush" Color="#EBCECE"></SolidColorBrush>
        <!--ScrollBar-->
        <SolidColorBrush x:Key="ScrollBarForeround" Color="#877F7F"></SolidColorBrush>
        <SolidColorBrush x:Key="ScrollBarBackground" Color="#3E3E42"></SolidColorBrush>

        <!--ItemsControl:DataGrid,Tree-->
        <system:Double x:Key="HeaderFontSize">14</system:Double>
        <SolidColorBrush x:Key="HeaderBorderBrush" Color="#A6FFA500"></SolidColorBrush>
        <SolidColorBrush x:Key="HeaderBackground" Color="Purple"></SolidColorBrush>
        <SolidColorBrush x:Key="ItemsContentBackground" Color="#1389D7"></SolidColorBrush>
        <SolidColorBrush x:Key="ItemsAlternationContentBackground" Color="#128EE0"></SolidColorBrush>
        <SolidColorBrush x:Key="GridLinesBrush" Color="#A6D0C2A7"></SolidColorBrush>
        <SolidColorBrush x:Key="ItemSelectedForeground" Color="White"></SolidColorBrush>
        <SolidColorBrush x:Key="ItemSelectedBackground" Color="#BC8BEA"></SolidColorBrush>
        <SolidColorBrush x:Key="ItemMouseOverBackground" Color="#BC8BEA"></SolidColorBrush>
        <SolidColorBrush x:Key="ItemMouseOverForeground" Color="White"></SolidColorBrush>
        <!--高亮:日历Today-->
        <SolidColorBrush x:Key="ItemHighlighteBackground" Color="#F0E5F1"></SolidColorBrush>
        <SolidColorBrush x:Key="ItemHighlighteForeground" Color="White"></SolidColorBrush>

        <!--普通无背景按钮-->
        <SolidColorBrush x:Key="CheckedForeground" Color="#F7B63E"></SolidColorBrush>
        <SolidColorBrush x:Key="MouseOverForeground" Color="Orange"></SolidColorBrush>
        <SolidColorBrush x:Key="PressedForeground" Color="Purple"></SolidColorBrush>
        <SolidColorBrush x:Key="LinkForeground" Color="#0816BB"></SolidColorBrush>
        <!--Popup,ComboBox-->
        <SolidColorBrush x:Key="PopupBackground" Color="White"></SolidColorBrush>
        <!--Button-->
        <SolidColorBrush x:Key="ButtonBackground" Color="#1D4A9A"></SolidColorBrush>
        <SolidColorBrush x:Key="ButtonForeground" Color="White"></SolidColorBrush>
        <SolidColorBrush x:Key="ButtonMouseOverBackground" Color="Orange"></SolidColorBrush>
        <SolidColorBrush x:Key="ButtonMouseOverForeground" Color="White"></SolidColorBrush>
        <SolidColorBrush x:Key="ButtonPressedBackground" Color="DarkOrange"></SolidColorBrush>
        <SolidColorBrush x:Key="ButtonPressedForeground" Color="White"></SolidColorBrush>
        <!--Menu-->
        <SolidColorBrush x:Key="MenuForeground" Color="#920892"></SolidColorBrush>
        <SolidColorBrush x:Key="MenuBackground" Color="#DDD1D1"></SolidColorBrush>
        <SolidColorBrush x:Key="MenuBorderBrush" Color="DarkBlue"></SolidColorBrush>
        <SolidColorBrush x:Key="MenuMouseOverBackground" Color="#0D3CD2"></SolidColorBrush>
        <SolidColorBrush x:Key="MenuMouseOverForeground" Color="White"></SolidColorBrush>
        <SolidColorBrush x:Key="MenuPressedBackground" Color="#082CA0"></SolidColorBrush>
        <SolidColorBrush x:Key="MenuPressedForeground" Color="White"></SolidColorBrush>
        <!--State brush-->
        <SolidColorBrush x:Key="SuccessfulfaiBrush" Color="#16B32A"></SolidColorBrush>
        <SolidColorBrush x:Key="FailedBrush" Color="#B92222"></SolidColorBrush>



        <Style x:Key="DatePickerCalendarStyle"
       TargetType="{x:Type Calendar}"
       >
            <Setter Property="Background" Value="White"></Setter>
            <Setter Property="FontSize" Value="18"></Setter>
            <Setter Property="CalendarButtonStyle" Value="{DynamicResource ButtonStyle}"></Setter>
            <Setter Property="CalendarDayButtonStyle" Value="{DynamicResource DayButtonStyle}"></Setter>
            <Setter Property="BorderBrush" Value="Purple"></Setter>
            <Setter Property="CalendarItemStyle" Value="{DynamicResource CalendarItemsStyle}"></Setter>
            
        </Style>
        <Style x:Key="ButtonStyle" TargetType="CalendarButton">
            <Setter Property="Background" Value="White"></Setter>
            <Setter Property="FontSize" Value="14"></Setter>
            <Setter Property="BorderBrush" Value="Transparent"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CalendarButton}">
                        <Grid x:Name="Grid" Margin="0">
                            <Border x:Name="Bg" Background="{TemplateBinding Background}" />
                            <ContentPresenter x:Name="NormalText" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          Margin="5,2,5,2" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          TextElement.Foreground="{TemplateBinding Foreground}" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="Purple"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="DayButtonStyle" TargetType="CalendarDayButton">
            <Setter Property="Background" Value="White"></Setter>
            <Setter Property="FontSize" Value="14"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CalendarDayButton}">
                        <Grid x:Name="Grid" Margin="0">
                            <Border x:Name="Bg" Background="{TemplateBinding Background}" BorderBrush="Purple" BorderThickness="0.5" />
                            <ContentPresenter x:Name="NormalText" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          Margin="5,2,5,2" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          TextElement.Foreground="{TemplateBinding Foreground}" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="Purple"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                            <Trigger Property="IsToday" Value="True">
                                <Setter Property="Background" Value="Gray"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="Purple"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


        <Style x:Key="FButton_Transparency" TargetType="{x:Type Button}">
            <Setter Property="Background" Value="White" />
            <Setter Property="Foreground" Value="Purple" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
            <Setter Property="Height" Value="Auto" />
            <Setter Property="Width" Value="Auto" />
            <Setter Property="FontSize" Value="13" />
            <Setter Property="Padding" Value="3,1,3,1" />
            <Setter Property="Cursor" Value="Hand"></Setter>
            <Setter Property="BorderBrush" Value="Transparent"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border Background="Transparent" BorderBrush="Transparent" BorderThickness="1">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="Purple"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="CalendarItemsStyle" TargetType="{x:Type CalendarItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type CalendarItem}">
                        <ControlTemplate.Resources>
                            <!-- 头部星期样式-->
                            <DataTemplate x:Key="{x:Static CalendarItem.DayTitleTemplateResourceKey}">
                                <TextBlock Text="{Binding}" FontWeight="Bold"  Foreground="{StaticResource PressedForeground}"
                                       FontSize="{StaticResource HeaderFontSize}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,6,0,6" Opacity="0.8" />
                            </DataTemplate>
                        </ControlTemplate.Resources>
                        <Grid x:Name="PART_Root">
                            <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="{TemplateBinding Background}" Margin="{TemplateBinding Margin}">
                                <Grid Margin="2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <!--Header-->
                                    <Grid Grid.Row="0" HorizontalAlignment="Stretch" Background="Transparent">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="2*"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <Button  x:Name="PART_PreviousButton"  Style="{StaticResource FButton_Transparency}"
                                                    Focusable="False" Grid.Column="0"  Content="←"  />
                                        <Button  x:Name="PART_HeaderButton" Style="{StaticResource FButton_Transparency}"  
                                                    Focusable="False" Grid.Column="1"  />

                                        <Button  x:Name="PART_NextButton"  Style="{StaticResource FButton_Transparency}"
                                                    Focusable="False" Grid.Column="2" Content="→" />
                                    </Grid>
                                    <!--PART_MonthView-->
                                    <Grid x:Name="PART_MonthView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="6,1,6,6" Grid.Row="1" Visibility="Visible">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                    </Grid>
                                    <!--PART_YearView-->
                                    <Grid x:Name="PART_YearView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="6,10,6,10" Grid.Row="1" Visibility="Hidden">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="*" />
                                        </Grid.RowDefinitions>
                                    </Grid>
                                </Grid>
                            </Border>
                        </Grid>
                         <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Opacity" TargetName="PART_Root" Value="{StaticResource DisableOpacity}" />
                        </Trigger>
                        <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Year">
                            <Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden" />
                            <Setter Property="Visibility" TargetName="PART_YearView" Value="Visible" />
                        </DataTrigger>
                        <!--Decade 美 ['dɛked] n. 十年,十年期;十-->
                        <DataTrigger Binding="{Binding DisplayMode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Calendar}}}" Value="Decade">
                            <Setter Property="Visibility" TargetName="PART_MonthView" Value="Hidden" />
                            <Setter Property="Visibility" TargetName="PART_YearView" Value="Visible" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        

        <!--The template for the button that displays the calendar.-->
        <Style x:Key="DropDownButtonStyle"
       TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualStateGroup.Transitions>
                                        <VisualTransition GeneratedDuration="0" />
                                        <VisualTransition GeneratedDuration="0:0:0.1"
                                  To="MouseOver" />
                                        <VisualTransition GeneratedDuration="0:0:0.1"
                                  To="Pressed" />
                                    </VisualStateGroup.Transitions>
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ColorAnimationUsingKeyFrames BeginTime="0"
                                                Duration="00:00:00.001"
                                                Storyboard.TargetName="BackgroundGradient"
                                                Storyboard.TargetProperty="(Border.Background).
                    (GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                <SplineColorKeyFrame KeyTime="0"
                                         Value="#F2FFFFFF" />
                                            </ColorAnimationUsingKeyFrames>
                                            <ColorAnimationUsingKeyFrames BeginTime="0"
                                                Duration="00:00:00.001"
                                                Storyboard.TargetName="BackgroundGradient"
                                                Storyboard.TargetProperty="(Border.Background).
                    (GradientBrush.GradientStops)[2].(GradientStop.Color)">
                                                <SplineColorKeyFrame KeyTime="0"
                                         Value="#CCFFFFFF" />
                                            </ColorAnimationUsingKeyFrames>
                                            <ColorAnimation Duration="0"
                                  To="#FF448DCA"
                                  Storyboard.TargetProperty="(Border.Background).
                            (SolidColorBrush.Color)"
                                  Storyboard.TargetName="Background" />
                                            <ColorAnimationUsingKeyFrames BeginTime="0"
                                                Duration="00:00:00.001"
                                                Storyboard.TargetName="BackgroundGradient"
                                                Storyboard.TargetProperty="(Border.Background).
                    (GradientBrush.GradientStops)[3].(GradientStop.Color)">
                                                <SplineColorKeyFrame KeyTime="0"
                                         Value="#7FFFFFFF" />
                                            </ColorAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ColorAnimationUsingKeyFrames BeginTime="0"
                                                Duration="00:00:00.001"
                                                Storyboard.TargetName="Background"
                                                Storyboard.TargetProperty="(Border.Background).
                      (SolidColorBrush.Color)">
                                                <SplineColorKeyFrame KeyTime="0"
                                         Value="#FF448DCA" />
                                            </ColorAnimationUsingKeyFrames>
                                            <DoubleAnimationUsingKeyFrames BeginTime="0"
                                                 Duration="00:00:00.001"
                                                 Storyboard.TargetProperty="(UIElement.Opacity)"
                                                 Storyboard.TargetName="Highlight">
                                                <SplineDoubleKeyFrame KeyTime="0"
                                          Value="1" />
                                            </DoubleAnimationUsingKeyFrames>
                                            <ColorAnimationUsingKeyFrames BeginTime="0"
                                                Duration="00:00:00.001"
                                                Storyboard.TargetName="BackgroundGradient"
                                                Storyboard.TargetProperty="(Border.Background).
                    (GradientBrush.GradientStops)[0].(GradientStop.Color)">
                                                <SplineColorKeyFrame KeyTime="0"
                                         Value="#F4FFFFFF" />
                                            </ColorAnimationUsingKeyFrames>
                                            <ColorAnimationUsingKeyFrames BeginTime="0"
                                                Duration="00:00:00.001"
                                                Storyboard.TargetName="BackgroundGradient"
                                                Storyboard.TargetProperty="(Border.Background).
                    (GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                <SplineColorKeyFrame KeyTime="0"
                                         Value="#EAFFFFFF" />
                                            </ColorAnimationUsingKeyFrames>
                                            <ColorAnimationUsingKeyFrames BeginTime="0"
                                                Duration="00:00:00.001"
                                                Storyboard.TargetName="BackgroundGradient"
                                                Storyboard.TargetProperty="(Border.Background).
                    (GradientBrush.GradientStops)[2].(GradientStop.Color)">
                                                <SplineColorKeyFrame KeyTime="0"
                                         Value="#C6FFFFFF" />
                                            </ColorAnimationUsingKeyFrames>
                                            <ColorAnimationUsingKeyFrames BeginTime="0"
                                                Duration="00:00:00.001"
                                                Storyboard.TargetName="BackgroundGradient"
                                                Storyboard.TargetProperty="(Border.Background).
                    (GradientBrush.GradientStops)[3].(GradientStop.Color)">
                                                <SplineColorKeyFrame KeyTime="0"
                                         Value="#6BFFFFFF" />
                                            </ColorAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled" />
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid Background="#11FFFFFF"
                FlowDirection="LeftToRight"
                HorizontalAlignment="Center"
                Height="18"
                Margin="0"
                VerticalAlignment="Center"
                Width="19">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="20*" />
                                    <ColumnDefinition Width="20*" />
                                    <ColumnDefinition Width="20*" />
                                    <ColumnDefinition Width="20*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="23*" />
                                    <RowDefinition Height="19*" />
                                    <RowDefinition Height="19*" />
                                    <RowDefinition Height="19*" />
                                </Grid.RowDefinitions>
                                <Border x:Name="Highlight"
                    BorderThickness="1"
                    Grid.ColumnSpan="4"
                    CornerRadius="0,0,1,1"
                    Margin="-1"
                    Opacity="1"
                    Grid.Row="0"
                    Grid.RowSpan="4">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Color="{DynamicResource ControlPressedColor}" />
                                    </Border.BorderBrush>
                                </Border>
                                <Border x:Name="Background"
                    BorderBrush="#FFFFFFFF"
                    BorderThickness="1"
                    Grid.ColumnSpan="4"
                    CornerRadius=".5"
                    Margin="0,-1,0,0"
                    Opacity="1"
                    Grid.Row="1"
                    Grid.RowSpan="3">
                                    <Border.Background>
                                        <SolidColorBrush Color="{DynamicResource ControlDarkColor}" />
                                    </Border.Background>
                                </Border>
                                <Border x:Name="BackgroundGradient"
                    BorderBrush="#BF000000"
                    BorderThickness="1"
                    Grid.ColumnSpan="4"
                    CornerRadius=".5"
                    Margin="0,-1,0,0"
                    Opacity="1"
                    Grid.Row="1"
                    Grid.RowSpan="3">
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint=".7,1"
                                     StartPoint=".7,0">
                                            <GradientStop Color="#FFFFFFFF"
                                Offset="0" />
                                            <GradientStop Color="#F9FFFFFF"
                                Offset="0.375" />
                                            <GradientStop Color="#E5FFFFFF"
                                Offset="0.625" />
                                            <GradientStop Color="#C6FFFFFF"
                                Offset="1" />
                                        </LinearGradientBrush>
                                    </Border.Background>
                                </Border>
                                <Rectangle Grid.ColumnSpan="4"
                       Grid.RowSpan="1"
                       StrokeThickness="1">
                                    <Rectangle.Fill>
                                        <LinearGradientBrush EndPoint="0,1"
                                     StartPoint="0,0">
                                            <GradientStop Color="{DynamicResource HeaderTopColor}" />
                                            <GradientStop Color="{DynamicResource ControlMediumColor}"
                                Offset="1" />
                                        </LinearGradientBrush>
                                    </Rectangle.Fill>
                                    <Rectangle.Stroke>
                                        <LinearGradientBrush EndPoint="0.48,-1"
                                     StartPoint="0.48,1.25">
                                            <GradientStop Color="#FF494949" />
                                            <GradientStop Color="#FF9F9F9F"
                                Offset="1" />
                                        </LinearGradientBrush>
                                    </Rectangle.Stroke>
                                </Rectangle>
                                <Path Fill="#FF2F2F2F"
                  Grid.Row="1"
                  Grid.Column="0"
                  Grid.RowSpan="3"
                  Grid.ColumnSpan="4"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  RenderTransformOrigin="0.5,0.5"
                  Margin="4,3,4,3"
                  Stretch="Fill"
                  Data="M11.426758,8.4305077 L11.749023,8.4305077 
                    L11.749023,16.331387 L10.674805,16.331387 
                    L10.674805,10.299648 L9.0742188,11.298672
                    L9.0742188,10.294277 C9.4788408,10.090176 
                    9.9094238,9.8090878 10.365967,9.4510155 
                    C10.82251,9.0929432 11.176106,8.7527733 
                    11.426758,8.4305077 z M14.65086,8.4305077 
                    L18.566387,8.4305077 L18.566387,9.3435936 
                    L15.671368,9.3435936 L15.671368,11.255703 
                    C15.936341,11.058764 16.27293,10.960293 
                    16.681133,10.960293 C17.411602,10.960293 
                    17.969301,11.178717 18.354229,11.615566 
                    C18.739157,12.052416 18.931622,12.673672
                    18.931622,13.479336 C18.931622,15.452317 
                    18.052553,16.438808 16.294415,16.438808
                    C15.560365,16.438808 14.951641,16.234707 
                    14.468243,15.826504 L14.881817,14.929531
                    C15.368796,15.326992 15.837872,15.525723 
                    16.289043,15.525723 C17.298809,15.525723 
                    17.803692,14.895514 17.803692,13.635098 
                    C17.803692,12.460618 17.305971,11.873379 
                    16.310528,11.873379 C15.83071,11.873379 
                    15.399232,12.079271 15.016094,12.491055
                    L14.65086,12.238613 z" />
                                <Ellipse Grid.ColumnSpan="4"
                     Fill="#FFFFFFFF"
                     HorizontalAlignment="Center"
                     Height="3"
                     StrokeThickness="0"
                     VerticalAlignment="Center"
                     Width="3" />
                                <Border x:Name="DisabledVisual"
                    BorderBrush="#B2FFFFFF"
                    BorderThickness="1"
                    Grid.ColumnSpan="4"
                    CornerRadius="0,0,.5,.5"
                    Opacity="0"
                    Grid.Row="0"
                    Grid.RowSpan="4" />
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="PickerStyle" TargetType="{x:Type DatePicker}">
            <Setter Property="Foreground"
          Value="#FF333333" />
            <Setter Property="IsTodayHighlighted"
          Value="True" />
            <Setter Property="SelectedDateFormat"
          Value="Short" />
            <Setter Property="Padding"
          Value="2" />
            <Setter Property="BorderThickness"
          Value="1" />
            <Setter Property="HorizontalContentAlignment"
          Value="Stretch" />
            <!--Set CalendarStyle to DatePickerCalendarStyle.-->
            <Setter Property="CalendarStyle"
          Value="{DynamicResource DatePickerCalendarStyle}" />
            <Setter Property="Width" Value="165"></Setter>
            <Setter Property="FontSize" Value="12"></Setter>
            <Setter Property="Height" Value="24"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DatePicker}">
                        <Border BorderThickness="{TemplateBinding BorderThickness}"
                Padding="{TemplateBinding Padding}">
                            <Border.BorderBrush>
                                <LinearGradientBrush EndPoint="0.5,1"
                                 StartPoint="0.5,0">
                                    <GradientStop Color="{DynamicResource BorderLightColor}"
                            Offset="1" />
                                    <GradientStop Color="{DynamicResource BorderDarkColor}"
                            Offset="1" />
                                </LinearGradientBrush>
                            </Border.BorderBrush>
                            <Border.Background>
                                <SolidColorBrush Color="Transparent"></SolidColorBrush>
                                <!--<LinearGradientBrush EndPoint="0.5,1"
                                 StartPoint="0.5,0">
                                    <GradientStop Color="{DynamicResource HeaderTopColor}"
                            Offset="0" />
                                    <GradientStop Color="{DynamicResource ControlMediumColor}"
                            Offset="1" />
                                </LinearGradientBrush>-->
                            </Border.Background>
                            <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.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"
                    Style="{StaticResource DropDownButtonStyle}"
                    VerticalAlignment="Top" Height="20" Background="Transparent" >
                                </Button>
                                <DatePickerTextBox x:Name="PART_TextBox"
                               Grid.Column="0"
                               Foreground="{TemplateBinding Foreground}"
                               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="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>
                </Setter.Value>
            </Setter>
        </Style>


        <!--Control colors.-->
        <Color x:Key="WindowColor">#FFE8EDF9</Color>
        <Color x:Key="ContentAreaColorLight">#FFC5CBF9</Color>
        <Color x:Key="ContentAreaColorDark">#FF7381F9</Color>

        <Color x:Key="DisabledControlLightColor">#FFE8EDF9</Color>
        <Color x:Key="DisabledControlDarkColor">#FFC5CBF9</Color>
        <Color x:Key="DisabledForegroundColor">#FF888888</Color>

        <Color x:Key="SelectedBackgroundColor">#FFC5CBF9</Color>
        <Color x:Key="SelectedUnfocusedColor">#FFDDDDDD</Color>

        <Color x:Key="ControlLightColor">White</Color>
        <Color x:Key="ControlMediumColor">#FF7381F9</Color>
        <Color x:Key="ControlDarkColor">#FF211AA9</Color>

        <Color x:Key="ControlMouseOverColor">#FF3843C4</Color>
        <Color x:Key="ControlPressedColor">#FF211AA9</Color>


        <Color x:Key="GlyphColor">#FF444444</Color>
        <Color x:Key="GlyphMouseOver">sc#1, 0.004391443, 0.002428215, 0.242281124</Color>

        <!--Border colors-->
        <Color x:Key="BorderLightColor">#FFCCCCCC</Color>
        <Color x:Key="BorderMediumColor">#FF888888</Color>
        <Color x:Key="BorderDarkColor">#FF444444</Color>

        <Color x:Key="PressedBorderLightColor">#FF888888</Color>
        <Color x:Key="PressedBorderDarkColor">#FF444444</Color>

        <Color x:Key="DisabledBorderLightColor">#FFAAAAAA</Color>
        <Color x:Key="DisabledBorderDarkColor">#FF888888</Color>

        <Color x:Key="DefaultBorderBrushDarkColor">Black</Color>

        <!--Control-specific resources.-->
        <Color x:Key="HeaderTopColor">#FFC5CBF9</Color>
        <Color x:Key="DatagridCurrentCellBorderColor">Black</Color>
        <Color x:Key="SliderTrackDarkColor">#FFC5CBF9</Color>

        <Color x:Key="NavButtonFrameColor">#FF3843C4</Color>

        <LinearGradientBrush x:Key="MenuPopupBrush"
                     EndPoint="0.5,1"
                     StartPoint="0.5,0">
            <GradientStop Color="{DynamicResource ControlLightColor}"
                Offset="0" />
            <GradientStop Color="{DynamicResource ControlMediumColor}"
                Offset="0.5" />
            <GradientStop Color="{DynamicResource ControlLightColor}"
                Offset="1" />
        </LinearGradientBrush>

        <LinearGradientBrush x:Key="ProgressBarIndicatorAnimatedFill"
                     StartPoint="0,0"
                     EndPoint="1,0">
            <LinearGradientBrush.GradientStops>
                <GradientStopCollection>
                    <GradientStop Color="#000000FF"
                    Offset="0" />
                    <GradientStop Color="#600000FF"
                    Offset="0.4" />
                    <GradientStop Color="#600000FF"
                    Offset="0.6" />
                    <GradientStop Color="#000000FF"
                    Offset="1" />
                </GradientStopCollection>
            </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>
    
</ResourceDictionary>
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WPF (Windows Presentation Foundation) 的 DatePicker 控件可以通过自定义样式来改变其外观和行为。要自定义 DatePicker样式,可以按照以下步骤进行操作: 1. 创建一个新的 WPF 项目,并在 XAML 文件中添加一个 DatePicker 控件。 2. 打开 DatePicker 控件的样式模板,可以通过在 XAML 中使用 `<DatePicker.Style>` 标签来指定样式。 3. 在样式模板中,可以自定义 DatePicker 的外观元素,比如边框、背景、按钮样式等。可以使用 XAML 标签来控制这些元素的属性和样式。 4. 若要自定义 DatePicker 的日期选择器弹出窗口的样式,可以在样式模板中添加 `<DatePicker.CalendarStyle>` 标签,并在其中定义日期选择器的样式。 5. 可以通过修改样式模板中的触发器和视觉状态来改变 DatePicker 在不同状态下的外观和行为。例如,可以自定义 DatePicker 在鼠标悬停或获取焦点时的效果。 6. 可以通过在样式模板中添加触发器或行为来定义 DatePicker 的交互行为。例如,可以添加一个触发器来在选择日期后自动关闭日期选择器弹出窗口。 7. 调整样式模板和元素的属性来满足个性化需求。可以更改颜色、字体、大小等属性,以及添加自定义绑定和动画效果。 自定义 DatePicker样式需要了解一些基本的 WPF 样式模板和控件元素的知识,以便能够正确地修改和调整样式。可以参考 MSDN 或其他 WPF 相关的教程、博客和文档来获取更多关于自定义样式的详细信息和示例代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值