wpf datepicker 样式

在项目中用到的

  1     <Style TargetType="{x:Type DatePicker}">
  2         <Setter Property="Foreground" Value="Black"/>
  3         <Setter Property="Width" Value="335"/>
  4         <Setter Property="Height" Value="73"/>
  5         <Setter Property="Focusable" Value="False"/>
  6         <Setter Property="VerticalContentAlignment" Value="Center"/>
  7         <Setter Property="IsTodayHighlighted" Value="True"/>
  8         <Setter Property="SelectedDateFormat" Value="Short"/>
  9         <Setter Property="Background" Value="White"/>
 10         <Setter Property="BorderThickness" Value="1"/>
 11         <Setter Property="BorderBrush" Value="#D2D6D9"/>
 12         <Setter Property="CalendarStyle" Value="{DynamicResource DatePickerCalendar}"/>
 13         <Setter Property="Template">
 14             <Setter.Value>
 15                 <ControlTemplate TargetType="{x:Type DatePicker}">
 16                     <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" >
 17                         <VisualStateManager.VisualStateGroups>
 18                             <VisualStateGroup x:Name="CommonStates">
 19                                 <VisualState x:Name="Normal"/>
 20                                 <VisualState x:Name="Disabled">
 21                                     <Storyboard>
 22                                         <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_DisabledVisual"/>
 23                                     </Storyboard>
 24                                 </VisualState>
 25                             </VisualStateGroup>
 26                         </VisualStateManager.VisualStateGroups>
 27                         <Grid x:Name="PART_Root" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
 28                             <Grid.Resources>
 29                                 <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF"/>
 30                                 <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
 31                                     <Grid>
 32                                         <VisualStateManager.VisualStateGroups>
 33                                             <VisualStateGroup x:Name="CommonStates">
 34                                                 <VisualStateGroup.Transitions>
 35                                                     <VisualTransition GeneratedDuration="0"/>
 36                                                     <VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/>
 37                                                     <VisualTransition GeneratedDuration="0:0:0.1" To="Pressed"/>
 38                                                 </VisualStateGroup.Transitions>
 39                                                 <VisualState x:Name="Normal"/>
 40                                                 <VisualState x:Name="MouseOver">
 41                                                     <Storyboard>
 42                                                         <ColorAnimation Duration="0" To="#FF448DCA" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Background"/>
 43                                                         <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">
 44                                                             <SplineColorKeyFrame KeyTime="0" Value="#7FFFFFFF"/>
 45                                                         </ColorAnimationUsingKeyFrames>
 46                                                         <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">
 47                                                             <SplineColorKeyFrame KeyTime="0" Value="#CCFFFFFF"/>
 48                                                         </ColorAnimationUsingKeyFrames>
 49                                                         <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">
 50                                                             <SplineColorKeyFrame KeyTime="0" Value="#F2FFFFFF"/>
 51                                                         </ColorAnimationUsingKeyFrames>
 52                                                     </Storyboard>
 53                                                 </VisualState>
 54                                                 <VisualState x:Name="Pressed">
 55                                                     <Storyboard>
 56                                                         <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Storyboard.TargetName="Background">
 57                                                             <SplineColorKeyFrame KeyTime="0" Value="#FF448DCA"/>
 58                                                         </ColorAnimationUsingKeyFrames>
 59                                                         <DoubleAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Highlight">
 60                                                             <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
 61                                                         </DoubleAnimationUsingKeyFrames>
 62                                                         <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">
 63                                                             <SplineColorKeyFrame KeyTime="0" Value="#EAFFFFFF"/>
 64                                                         </ColorAnimationUsingKeyFrames>
 65                                                         <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">
 66                                                             <SplineColorKeyFrame KeyTime="0" Value="#C6FFFFFF"/>
 67                                                         </ColorAnimationUsingKeyFrames>
 68                                                         <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">
 69                                                             <SplineColorKeyFrame KeyTime="0" Value="#6BFFFFFF"/>
 70                                                         </ColorAnimationUsingKeyFrames>
 71                                                         <ColorAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetProperty="(Border.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="BackgroundGradient">
 72                                                             <SplineColorKeyFrame KeyTime="0" Value="#F4FFFFFF"/>
 73                                                         </ColorAnimationUsingKeyFrames>
 74                                                     </Storyboard>
 75                                                 </VisualState>
 76                                                 <VisualState x:Name="Disabled"/>
 77                                             </VisualStateGroup>
 78                                         </VisualStateManager.VisualStateGroups>
 79                                         <Grid Background="Transparent" FlowDirection="LeftToRight" HorizontalAlignment="Center" Height="18" Margin="0" VerticalAlignment="Center" Width="19">
 80                                             <Grid.ColumnDefinitions>
 81                                                 <ColumnDefinition Width="20*"/>
 82                                                 <ColumnDefinition Width="20*"/>
 83                                                 <ColumnDefinition Width="20*"/>
 84                                                 <ColumnDefinition Width="20*"/>
 85                                             </Grid.ColumnDefinitions>
 86                                             <Grid.RowDefinitions>
 87                                                 <RowDefinition Height="23*"/>
 88                                                 <RowDefinition Height="19*"/>
 89                                                 <RowDefinition Height="19*"/>
 90                                                 <RowDefinition Height="19*"/>
 91                                             </Grid.RowDefinitions>
 92                                             <Border x:Name="Highlight" Visibility="Hidden" BorderBrush="#FF45D6FA" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius="0,0,1,1" Margin="-1" Opacity="0" Grid.Row="0" Grid.RowSpan="4"/>
 93                                             <Border x:Name="Background" Visibility="Hidden" BorderBrush="#FFFFFFFF" BorderThickness="1" Background="#FF1F3B53" Grid.ColumnSpan="4" CornerRadius=".5" Margin="0,-1,0,0" Opacity="1" Grid.Row="1" Grid.RowSpan="3"/>
 94                                             <Border x:Name="BackgroundGradient" Visibility="Hidden" BorderBrush="#BF000000" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius=".5" Margin="0,-1,0,0" Opacity="1" Grid.Row="1" Grid.RowSpan="3">
 95                                                 <Border.Background>
 96                                                     <LinearGradientBrush EndPoint=".7,1" StartPoint=".7,0">
 97                                                         <GradientStop Color="#FFFFFFFF" Offset="0"/>
 98                                                         <GradientStop Color="#F9FFFFFF" Offset="0.375"/>
 99                                                         <GradientStop Color="#E5FFFFFF" Offset="0.625"/>
100                                                         <GradientStop Color="#C6FFFFFF" Offset="1"/>
101                                                     </LinearGradientBrush>
102                                                 </Border.Background>
103                                             </Border>
104                                             <Rectangle Visibility="Hidden" Grid.ColumnSpan="4" Grid.RowSpan="1" StrokeThickness="1">
105                                                 <Rectangle.Fill>
106                                                     <LinearGradientBrush EndPoint="0.3,-1.1" StartPoint="0.46,1.6">
107                                                         <GradientStop Color="#FF4084BD"/>
108                                                         <GradientStop Color="#FFAFCFEA" Offset="1"/>
109                                                     </LinearGradientBrush>
110                                                 </Rectangle.Fill>
111                                                 <Rectangle.Stroke>
112                                                     <LinearGradientBrush EndPoint="0.48,-1" StartPoint="0.48,1.25">
113                                                         <GradientStop Color="#FF494949"/>
114                                                         <GradientStop Color="#FF9F9F9F" Offset="1"/>
115                                                     </LinearGradientBrush>
116                                                 </Rectangle.Stroke>
117                                             </Rectangle>
118                                             <Path Grid.ColumnSpan="4" Grid.Column="0" Data="M 0 0 L 4 6 L 8 0" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}" HorizontalAlignment="Center" Margin="4,3,4,3" Grid.Row="1" Grid.RowSpan="3" RenderTransformOrigin="0.5,0.5" VerticalAlignment="Center"/>
119                                             <Ellipse Visibility="Hidden" Grid.ColumnSpan="4" Fill="#FFFFFFFF" HorizontalAlignment="Center" Height="3" StrokeThickness="0" VerticalAlignment="Center" Width="3"/>
120                                             <Border x:Name="DisabledVisual" Visibility="Hidden" BorderBrush="#B2FFFFFF" BorderThickness="1" Grid.ColumnSpan="4" CornerRadius="0,0,.5,.5" Opacity="0" Grid.Row="0" Grid.RowSpan="4"/>
121                                         </Grid>
122                                     </Grid>
123                                 </ControlTemplate>
124                             </Grid.Resources>
125                             <Grid.ColumnDefinitions>
126                                 <ColumnDefinition Width="*"/>
127                                 <ColumnDefinition Width="Auto"/>
128                             </Grid.ColumnDefinitions>
129                             <!--<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="Center" Width="20"/>-->
130                             <Button x:Name="PART_Button" Grid.Column="1" Foreground="{TemplateBinding Foreground}" Focusable="False" HorizontalAlignment="Left" Margin="3,0,3,0" Grid.Row="0"  VerticalAlignment="Center" Width="60" Height="73" Background="Transparent" >
131                                 <Button.Content>
132                                     <Image Source="/View/Resources/pop_ico_calendar.png" Height="55"/>
133                                 </Button.Content>
134                             </Button>
135                             <DatePickerTextBox x:Name="PART_TextBox" Text="{TemplateBinding Tag}" Grid.Column="0" IsHitTestVisible="False" Focusable="False" HorizontalContentAlignment="Center" Grid.Row="0" VerticalContentAlignment="Center" FontStyle="Normal" FontSize="32" Foreground="#484C50" Height="73" BorderThickness="0,0,2,0" BorderBrush="#F0F0F0" Background="Transparent" />
136                             <Grid x:Name="PART_DisabledVisual" Grid.ColumnSpan="2" Grid.Column="0" IsHitTestVisible="False" Opacity="0" Grid.Row="0" Height="73">
137                                 <Grid.ColumnDefinitions>
138                                     <ColumnDefinition Width="*"/>
139                                     <ColumnDefinition Width="Auto"/>
140                                 </Grid.ColumnDefinitions>
141                                 <!--<Rectangle Grid.Column="0" Fill="#A5FFFFFF" RadiusY="1" Grid.Row="0" RadiusX="1"/>-->
142                                 <!--<Rectangle Grid.Column="1" Fill="#A5FFFFFF" Height="18" Margin="3,0,3,0" RadiusY="1" Grid.Row="0" RadiusX="1" Width="19"/>-->
143                                 <Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>
144                             </Grid>
145                         </Grid>
146                     </Border>
147                     <ControlTemplate.Triggers>
148                         <DataTrigger Binding="{Binding Source={x:Static SystemParameters.HighContrast}}" Value="false">
149                             <Setter Property="Foreground" TargetName="PART_TextBox" Value="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"/>
150                         </DataTrigger>
151                         <Trigger Property="IsMouseOver"  Value="True">
152                             <Setter Property="Opacity" Value="0.8"/>
153                         </Trigger>
154                         <Trigger Property="IsDropDownOpen" Value="True">
155                             <Setter Property="Opacity" Value="1"/>
156                         </Trigger>
157                     </ControlTemplate.Triggers>
158                 </ControlTemplate>
159             </Setter.Value>
160         </Setter>
161     </Style>

效果如下:

原文地址:https://www.cnblogs.com/dotnetHui/p/8600656.html

时间: 2024-10-19 09:02:05

wpf datepicker 样式的相关文章

WPF自定义样式篇-DataGrid

WPF自定义样式篇-DataGrid 先上效果图: 样式: <!--DataGrid样式-->    <Style TargetType="DataGrid">        <Setter Property="RowHeaderWidth" Value="0"></Setter>        <Setter Property="AutoGenerateColumns"

求助 WPF ListViewItem样式问题

求助 WPF ListViewItem样式问题 .NET 开发 > Windows Presentation Foundation Вопрос 0 Нужно войти <Style TargetType="ListViewItem"> <!--<Setter Property="Margin" Value="0,1,0,0"/>--> <Setter Property="Height

WPF设置样式的几种方式

第一种方式是直接使用Setter来进行,可以对Background等进行设置. <Window.Resources> <Style TargetType="Button"> <Setter Property="Background" Value="Red"/> </Style></Window.Resources> 第二种是直接将比较复杂一点的Style放置到Window.Resourc

WPF DatePicker

WPF DatePicker 显示当前时间 1.通过后台赋值: DatePicker.SelectedDate = DateTime.Now; 2.前台控件的属性直接赋值 <DatePicker SelectedDate="{x:Static sys:DateTime.Now}" /> 需要引用 xmlns:sys="clr-namespace:System;assembly=mscorlib"

WPF DataGrid 样式设置

隔行换色,鼠标单击,悬浮样式都有,其具体效果如图 1 所示. 图 1 WPF DataGrid 样式设置效果图 其中: 界面设计代码下所示 ? + 查看代码 1 2 3 4 5 6 7 8 9 10 11 12 <DataGrid AutoGenerateColumns="False"  Name="dataGrid1"  VerticalAlignment="Top"       CanUserSortColumns="Fals

WPF中样式和行为和触发器

原文:WPF中样式和行为和触发器 样式简介:样式(style)是组织和重用格式化选项的重要工具,不是使用重复的标记填充XAML,以便设置外边距.内边距.颜色以及字体等细节.而是创建一系列封装所有这些细节的样式,然后在需要之处通过属性来设置样式.名称空间是System.Windows. 1.样式. 为了理解适合使用样式的集合,分析一个简单的示例,设想需要标准化在窗口中使用的字体,最简单的方式是设置包含窗口的字体属性,这些属性都是在Control类中定义的,包括FontFamily.FontSize

WPF DatePicker默认显示当前日期,格式化为年月日(转)

WPF DatePicker默认显示当前日期,格式化为年月日 2018年08月08日 11:23:00 weixin_33922670 阅读数:253 原文:WPF DatePicker默认显示当前日期 WPF的日历选择控件默认为当前日期,共有两种方法,一种静态,一种动态. 静态的当然写在DatePicker控件的属性里了,动态的写在对应的cs文件里,具体请看下面. 1.方法一: myDatePicker.Text = DateTime.Today.ToLongDateString(); 2.方

Wpf DatePicker范围选择限制(转)

Wpf DatePicker范围选择限制 2018年06月06日 14:44:53 木子帅 阅读数:1265 版权声明: https://blog.csdn.net/yedekuqi4712/article/details/80594606 需要实现:两个DatePicker,(1)第一个选择时间后,再选择第二个,不能在第一个时间之前:(2)第二个选择后,再选择第一个,不能在第二个时间之后. 代码: <DatePicker Height="25"   HorizontalAlig

WPF之样式——style

wpf这门编写winform程序的技术相比常规的winform技术有一个很显著的特点--炫! 怎么才能炫起来呢? 我们都知道常规的winform技术就是拖控件,总的来说想用常规的winform技术来实现很好看的界面很难. 但是wpf就可以实现起来很轻松. 有过web知识的童鞋很好理解,咱们看到的网站大部分都比winfrom好看的多,为啥? 因为里面所有的控件都是程序人员拿HTML编写的,编程人员可以自由的定义控件的样式.我们的WPF一样可以轻松的定义控件的样式. 下面我们一起来体验一下: 我们建