Page view counter
How to get dd-MM-yyyy date format in DatePicker control? Subscribe to this thread
Last post 11-25-2008 11:43 PM by hoangtuit. 3 replies.
Sort Posts:
11-25-2008 1:03 AM
How to get dd-MM-yyyy date format in DatePicker control?

I can set dd-MMM-yyy date format in DatePicker, but I can't set dd-MM-yyyy.

 This is my code:

        private void ToDay_Loaded(object sender, RoutedEventArgs e)
        {
            this.ToDay.Text = DateTime.Now.ToString("dd-MM-yyyy");
        }

        private void ToDay_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            this.ToDay.Text = this.ToDay.SelectedDate.Value.ToString("dd-MM-yyyy");
            DrawReservation();
        }

 Please help me.

hoangtuit

Loading...
Joined on 11-08-2008
Posts 24
11-25-2008 4:59 PM
Re: How to get dd-MM-yyyy date format in DatePicker control?

<UserControl x:Class="ClinicalApp.Silverlight

xmlns:control="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"

xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"

xmlns:Systemcontrol="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"

xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" xmlns:System_Windows_Controls_Primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"

Width="32" Height="210">

<UserControl.Resources>

<model:DateFormatter x:Key="DateConverter" />

<DataTemplate x:Key="CellTemplateDate">

<TextBlock TextWrapping="NoWrap" Text="{Binding Converter={StaticResource DateConverter}, ConverterParameter=\{0:dd-MMM-yyyy\}, Path=StartDate}"

Margin="4"/>

</DataTemplate>

 

<DataTemplate x:Key="CellEditingTemplateDate">

<Systemcontrol:DatePicker

SelectedDate="{Binding StartDate, Mode=TwoWay}" />

</DataTemplate>

</UserControl.Resources>

 

public class DateFormatter : IValueConverter

{

#region IValueConverter Members

 

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

{

if (parameter != null)

{

string formatterString = parameter.ToString();if (!string.IsNullOrEmpty(formatterString))

{

return string.Format(culture, formatterString, value);

}

}

return value.ToString();

}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

{

//throw new NotImplementedException();

return value;

}

#endregion

}

thanks
Prasad Bhalekar (PP)
Please "Mark as Answer" if any of my content helped resolve the issue

Prasad Bhalekar

Loading...
Joined on 11-19-2008
Louisville KY USA
Posts 39
11-25-2008 11:11 PM
Marked as Answer
Re: How to get dd-MM-yyyy date format in DatePicker control?

Hi hoangtuit,

Add   using System.Globalization;using System.Threading;   Namespace

And

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB"); in your code behind ...

Cheers,
Balakrishnan

Whitewing_s

Loading...
Joined on 07-03-2008
Bangalore
Posts 107
11-25-2008 11:43 PM
Re: How to get dd-MM-yyyy date format in DatePicker control?

 Thanks Whitewing_s.

I got it.

hoangtuit

Loading...
Joined on 11-08-2008
Posts 24
Microsoft Communities