Click here to Skip to main content
15,898,745 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i have datepicker style and it is applyed to two datepicker controls(Same window) with date format dd-MMM-yyyy. But the problem i am facing is. if i select one date picker the selected date is comming in correct format(06-JUL-2017) and if i select second date picker first date picker fromat is changing to 06-07-2017 and second datepicker format is comming correctly...vice versa... so what is the solution for this?

What I have tried:

tried to apply different style to different datepicker but still facing same problem
Posted
Updated 1-Aug-17 7:37am
Comments
Erik Rude 6-Jul-17 7:52am    
Share your code if you want to get a response other than this type, please.
Try making it contain a working sample of the behaviour you're getting (include the style and the xaml.
Member 11559270 7-Jul-17 1:01am    
how to attach my sample project here???
Erik Rude 7-Jul-17 4:12am    
You can paste the code into the editor. If you have a small code sample that people can look at it will work best.
Member 11559270 7-Jul-17 7:13am    
//Style


<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Foreground" Value="#FF01579B" />
<Setter Property="FontFamily" Value="pack://application:,,,/WpfControlLibrary_Common;Component/Fonts/#Roboto Medium" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Template">
<Setter.Value>
&lt;ControlTemplate TargetType="Button">
&lt;Canvas Name="svg2"
Width="24"
Height="24">
<Canvas.RenderTransform>
&lt;TranslateTransform X="0" Y="0" />
</canvas.RenderTransform>
&lt;Canvas.Resources />
&lt;Canvas Name="layer1">
&lt;Path Name="SelectionArea"
Data="M0 0h24v24H0z"
Fill="Transparent" />
&lt;Path Name="GeometryPath" Fill="#9e9e9e" />
</canvas>
</canvas>
<ControlTemplate.Triggers>
&lt;Trigger Property="Button.Content" Value="Last">
&lt;Setter TargetName="GeometryPath" Property="Data" Value="M5.59 7.41L10.18 12l-4.59 4.59L7 18l6-6-6-6zM16 6h2v12h-2z" />
</trigger>
&lt;Trigger Property="Button.Content" Value="Next">
&lt;Setter TargetName="GeometryPath" Property="Data" Value="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z" />
</trigger>
&lt;Trigger Property="Button.Content" Value="First">
&lt;Setter TargetName="GeometryPath" Property="Data" Value="M18.41 16.59L13.82 12l4.59-4.59L17 6l-6 6 6 6zM6 6h2v12H6z" />
</trigger>
&lt;Trigger Property="Button.Content" Value="Previous">
&lt;Setter TargetName="GeometryPath" Property="Data" Value="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z" />
</trigger>
&lt;Trigger Property="IsMouseOver" Value="True">
&lt;Setter TargetName="GeometryPath" Property="Fill" Value="#757575" />
</trigger>
&lt;Trigger Property="IsPressed" Value="True">
&lt;Setter TargetName="GeometryPath" Property="Fill" Value="#616161" />
</trigger>
&lt;Trigger Property="IsEnabled" Value="False">
&lt;Setter TargetName="GeometryPath" Property="Fill" Value="#E0E0E0" />
</trigger>
</controltemplate.Triggers>
</controltemplate>
</setter.Value>
</setter>


<Color x:Key="ThemeColors">#ff7fbb
<Color x:Key="darkBlueColor">Black
<Color x:Key="lightBlueColor">#ff7fbb
<Color x:Key="MFontColor">#FF757575
<SolidColorBrush x:Key="darkBlueSolidBrush" Color="{DynamicResource darkBlueColor}" />
<SolidColorBrush x:Key="lightBlueSolidBrush" Color="{DynamicResource lightBlueColor}" />
<SolidColorBrush x:Key="ThemeColor" Color="{DynamicResource ThemeColors}"/>



&lt;Setter Property="Background"
Erik Rude 7-Jul-17 7:43am    
Have a look at some of the questions that has a successful answer. Do what they did. Show what you have that doesn't work for you in the question. The above style is probably fine, but what does your code do - what have you done? And change it in your question - not everybody wants to read comments all day :)

1 solution

Try to use below given style for DatePickerTextBox instead of DatePicker.

<Style TargetType="{x:Type DatePickerTextBox}">
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <TextBox BorderThickness="0" Style="{x:Null}" x:Name="PART_TextBox"
     Text="{Binding Path=SelectedDate, StringFormat='dd-MMM-yyyy', 
     RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>


Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900