Date/Time Picker (Win8) #100

Closed
ghost opened this Issue May 23, 2012 · 5 comments

Comments

Projects
None yet
2 participants
@ghost

ghost commented May 23, 2012

Win8/Metro has a "date/time" picker set of controls that look like

WPF's inbuilt datetimepicker is garbage. A control (not just restyling) would be needed. There is (for Win8/WinRT) Callisto that implements such a control in XAML/C#, but I haven't checked what it actually looks like yet.

Alternatively, restyling existing third-party controls might be a better approach

@ghost

ghost commented May 28, 2012

Work started in the DatePicker branch.
Currently looks like:

I'm unsure if year should be an option,

@ghost

ghost commented May 28, 2012

Should probably also have an option to flip the date based on the current culture (ie, month-day, for those backwards Americans)

Unknown referenced this issue Aug 23, 2012

Closed

Metro-style classical DatePicker #176

Hey, I am using the Metro Style in my application and I found necessary to style the default WPF Datepicker to look similar to the other Metro controls. I don't have permission to add any code to this project, so if it helps anyone below are the style:

< ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:Converters="clr-namespace:MahApps.Metro.Converters">

<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<Converters:ThicknessToDoubleConverter x:Key="ThicknessToDoubleConverter"/>



<Style TargetType="{x:Type DatePicker}" x:Key="DatePicker">
    <Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
    <Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
    <Setter Property="MinHeight" Value="26" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="IsTodayHighlighted" Value="True" />
    <Setter Property="SelectedDateFormat" Value="Short" />
    <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}" />
    <Setter Property="Padding" Value="0"/>
    <Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorderBrush}" />
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="Template">
           <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePicker}">

                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="ValidationStates">
                            <VisualState x:Name="Valid" />
                            <VisualState x:Name="InvalidUnfocused">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ValidationErrorElement">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="InvalidFocused">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ValidationErrorElement">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen" Storyboard.TargetName="validationTooltip">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <System:Boolean>True</System:Boolean>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup Name="CommonStates">
                            <VisualState Name="Normal" />
                            <VisualState Name="Disabled">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="PART_DisabledVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Rectangle x:Name="Base" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}}" Opacity="1" Fill="{TemplateBinding Background}" />
                    <Rectangle x:Name="FocusRectangle" StrokeThickness="{TemplateBinding BorderThickness, Converter={StaticResource ThicknessToDoubleConverter}}" Opacity="0" Stroke="{DynamicResource BlackBrush}" />
                    <Border  
                        Padding="{TemplateBinding Padding}">
                        <Border.Child>
                            <Grid x:Name="PART_Root"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                <Grid.Resources>
                                    <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF" />

                                    <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="Button">
                                        <Grid>
                                            <VisualStateManager.VisualStateGroups>
                                                <VisualStateGroup Name="CommonStates">
                                                    <VisualStateGroup.Transitions>
                                                        <VisualTransition GeneratedDuration="0" />
                                                        <VisualTransition To="MouseOver" GeneratedDuration="0:0:0.1" />
                                                        <VisualTransition To="Pressed" GeneratedDuration="0:0:0.1" />
                                                    </VisualStateGroup.Transitions>
                                                    <VisualState Name="Normal" />
                                                    <VisualState Name="MouseOver">
                                                        <Storyboard>

                                                            <DoubleAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetName="Hover" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                                <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                                            </DoubleAnimationUsingKeyFrames>

                                                        </Storyboard>
                                                    </VisualState>
                                                    <VisualState Name="Pressed">
                                                        <Storyboard>

                                                            <DoubleAnimationUsingKeyFrames BeginTime="0" Duration="00:00:00.001" Storyboard.TargetName="Highlight" Storyboard.TargetProperty="(UIElement.Opacity)">
                                                                <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                                            </DoubleAnimationUsingKeyFrames>

                                                        </Storyboard>
                                                    </VisualState>
                                                    <VisualState Name="Disabled" />
                                                </VisualStateGroup>
                                            </VisualStateManager.VisualStateGroups>

                                            <Grid Height="18" Width="19" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0" Background="#11FFFFFF" FlowDirection="LeftToRight">
                                                <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 Margin="-1" Grid.ColumnSpan="4" Grid.Row="0" Grid.RowSpan="4" BorderThickness="1" BorderBrush="#BF000000" Opacity="0" CornerRadius="0,0,1,1" x:Name="Highlight"/>
                                                <Border Margin="-1" Grid.ColumnSpan="4" Grid.Row="0" Grid.RowSpan="4" BorderThickness="1" BorderBrush="{StaticResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" Opacity="0" CornerRadius="0,0,1,1" x:Name="Hover"/>
                                                <Border x:Name="Background" Margin="0,-1,0,0" Grid.ColumnSpan="4" Grid.Row="1" Grid.RowSpan="3" BorderThickness="1" BorderBrush="#FFFFFFFF" Opacity="1" CornerRadius=".5" Background="#FF1F3B53"/>
                                                <Border x:Name="BackgroundGradient" Margin="0,-1,0,0" Grid.ColumnSpan="4" Grid.Row="1" Grid.RowSpan="3" BorderThickness="1" BorderBrush="#BF000000" Opacity="1" CornerRadius=".5">
                                                    <Border.Background>
                                                        <LinearGradientBrush StartPoint=".7,0" EndPoint=".7,1">
                                                            <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.Stroke>
                                                        <LinearGradientBrush EndPoint="0.48,-1" StartPoint="0.48,1.25">
                                                            <GradientStop Color="#FF494949"/>
                                                            <GradientStop Color="#FF9F9F9F" Offset="1"/>
                                                        </LinearGradientBrush>
                                                    </Rectangle.Stroke>
                                                    <Rectangle.Fill>
                                                        <LinearGradientBrush EndPoint="0.3,-1.1" StartPoint="0.46,1.6">
                                                            <GradientStop Color="#FF4084BD"/>
                                                            <GradientStop Color="#FFAFCFEA" Offset="1"/>
                                                        </LinearGradientBrush>
                                                    </Rectangle.Fill>
                                                </Rectangle>
                                                <Path HorizontalAlignment="Center" Margin="4,3,4,3" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" Grid.Column="0" Grid.Row="1" Fill="#FF2F2F2F" 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" Grid.ColumnSpan="4" Grid.RowSpan="3"/>
                                                <Ellipse HorizontalAlignment="Center" VerticalAlignment="Center" Fill="#FFFFFFFF" StrokeThickness="0" Grid.ColumnSpan="4" Width="3" Height="3"/>
                                                <Border Grid.ColumnSpan="4" Grid.Row="0" Grid.RowSpan="4" BorderThickness="1" BorderBrush="#B2FFFFFF" Opacity="0" CornerRadius="0,0,.5,.5" x:Name="DisabledVisual"/>

                                        </Grid>
                                        </Grid>

                                    </ControlTemplate>
                                </Grid.Resources>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Button x:Name="PART_Button" Grid.Row="0" Grid.Column="1"
                                    Template="{StaticResource DropDownButtonTemplate}"
                                    Foreground="{TemplateBinding Foreground}" 
                                    Width="20"
                                    Margin="3,0,3,0" 
                                    Focusable="False" 
                                    VerticalAlignment="Top"
                                    HorizontalAlignment="Left" />
                                <DatePickerTextBox x:Name="PART_TextBox" 
                                Grid.Row="0" Grid.Column="0" 
                                Foreground="{TemplateBinding Foreground}" 
                                HorizontalContentAlignment="Stretch"
                                VerticalContentAlignment="Stretch"
                                                   Height="18"
                                 Margin="2,0.5,1,1"                     
                                Focusable="{TemplateBinding Focusable}" />
                                <Grid x:Name="PART_DisabledVisual" 
                                  Opacity="0" 
                                  IsHitTestVisible="False" 
                                  Grid.Row="0" Grid.Column="0"
                                  Grid.ColumnSpan="2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Rectangle Grid.Row="0" Grid.Column="0" RadiusX="1" RadiusY="1" Fill="#A5FFFFFF"/>
                                    <Rectangle Grid.Row="0" Grid.Column="1" RadiusX="1" RadiusY="1" Fill="#A5FFFFFF" Height="18" Width="19" Margin="3,0,3,0" />
                                    <Popup x:Name="PART_Popup" 
                                       PlacementTarget="{Binding ElementName=PART_TextBox}"
                                       Placement="Bottom" 
                                       StaysOpen="False"
                                       AllowsTransparency="True" />

                                </Grid>


                        </Grid>
                        </Border.Child>

                    </Border>
                    <Border x:Name="ValidationErrorElement" BorderBrush="{DynamicResource ControlsValidationBrush}" BorderThickness="1" Visibility="Collapsed">
                        <ToolTipService.ToolTip>
                        <ToolTip x:Name="validationTooltip"
                                     DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                     Placement="Right"
                                     PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                     Template="{DynamicResource ValidationToolTipTemplate}">
                            <!--<ToolTip.Triggers>
                                    <EventTrigger RoutedEvent="Canvas.Loaded">
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible" Storyboard.TargetName="validationTooltip">
                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                        <DiscreteObjectKeyFrame.Value>
                                                            <System:Boolean>true</System:Boolean>
                                                        </DiscreteObjectKeyFrame.Value>
                                                    </DiscreteObjectKeyFrame>
                                                </ObjectAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </EventTrigger>
                                </ToolTip.Triggers>-->

                        </ToolTip>
                    </ToolTipService.ToolTip>
                    <Grid Background="Transparent" HorizontalAlignment="Right" Height="12" Margin="1,-4,-4,0" VerticalAlignment="Top" Width="12">
                        <Path Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z" Fill="{DynamicResource ValidationBrush5}" Margin="1,3,0,0" />
                        <Path Data="M 0,0 L2,0 L 8,6 L8,8" Fill="{DynamicResource WhiteColorBrush}" Margin="1,3,0,0" />
                    </Grid>
                </Border>

                </Grid>
            <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="FocusRectangle" Property="Opacity" Value="1" />
                    </Trigger>
                    <Trigger Property="IsFocused" Value="True">
                        <Setter TargetName="FocusRectangle" Property="Opacity" Value="1" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
            </Setter.Value>
        </Setter>
</Style>

<Style TargetType="{x:Type DatePickerTextBox}" x:Key="DatePickerTextBox">
    <Setter Property="Controls:TextboxHelper.IsMonitoring" Value="True"/>
    <Setter Property="SelectionBrush" Value="{DynamicResource HighlightBrush}" />
    <Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
    <Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorderBrush}" />
    <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    <Setter Property="MinHeight" Value="18" />

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="DatePickerTextBox">
                <Grid>
                    <Grid.Resources>
                        <SolidColorBrush x:Key="WatermarkBrush" Color="#FFAAAAAA"/>
                    </Grid.Resources>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup Name="CommonStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0" />
                                <VisualTransition To="MouseOver" GeneratedDuration="0:0:0.1" />
                            </VisualStateGroup.Transitions>
                            <VisualState Name="Normal" />
                            <VisualState Name="MouseOver">

                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup Name="WatermarkStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0" />
                            </VisualStateGroup.Transitions>
                            <VisualState Name="Unwatermarked" />
                            <VisualState Name="Watermarked">
                                <Storyboard>

                                    <DoubleAnimation Storyboard.TargetName="PART_Watermark" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup Name="FocusStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0" />
                            </VisualStateGroup.Transitions>
                            <VisualState Name="Unfocused" />
                            <VisualState Name="Focused">

                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>


                    <Border x:Name="Border" 
                            Background="{DynamicResource ControlBackgroundBrush}">
                        <Grid x:Name="WatermarkContent"
                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}">

                            <Border x:Name="watermark_decorator" BorderThickness="1">
                                <Border.BorderBrush>
                                    <SolidColorBrush Color="#FFFFFFFF"/>
                                </Border.BorderBrush>
                                <ContentControl x:Name="PART_Watermark"
                                                    Opacity="0"
                                                    Focusable="False"
                                                    IsHitTestVisible="False"
                                                    Padding="2"/>
                            </Border>
                            <ScrollViewer x:Name="PART_ContentHost" 
                                          Margin="0"
                                          HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                          VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />

                        </Grid>
                    </Border>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

< /ResourceDictionary >

Member

flagbug commented Aug 26, 2012

@mateusbello Why don't you just create a pull request?

@flagbug Oh, didn't know I could do that. It's done.
The only way I dounf do it was to fork the project, add a new branch and than create a pull request. Is that the correct way?
I tried to create a new branch on the main project but I got an error message when trying to publish my new branch.

Unknown referenced this issue Aug 27, 2012

Closed

DatePickerStyle #184

ghost closed this Dec 16, 2012

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment