I am working with a DatePicker
in a WPF application. I want to change the date format of the DatePicker
to the system date format.
This is the mail window:
<Window x:Class="DateTimeDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<Button x:Name="Btn" Width="100" Click="Btn_Click">Click</Button>
</StackPanel>
</Window>
The child window is opened using the following code:
private void Btn_Click(object sender, RoutedEventArgs e)
{
ChiildWindow Cw = new ChiildWindow();
Cw.ChildDatePicker.SelectedDate = DateTime.Now;
Cw.ShowDialog();
Cw.Focus();
}
This is the child window, which only contains a DatePicker
:
<Window x:Class="DateTimeDemo.ChiildWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ChiildWindow" Height="300" Width="300">
<StackPanel>
<DatePicker x:Name="ChildDatePicker"/>
</StackPanel>
</Window>
When I open the child window the format is taken from the system culture but if I change the system date format from the control panel after the window opens the format doesn't change.
I have tried the following code in the ChildWindow.xaml.cs file:
Thread.CurrentThread.CurrentCulture = CultureInfo.CurrentCulture;
But when I open the child window the format doesn't change.
Does anyone know what the problem is and how I can solve this issue?