I have following problem.
My application shows some data in datagrid and one of the datagrid columns contains date and time that is shown in system format.
When I change system format of date or time (Change date and time settings -> Change date and time -> Change calendar settings -> Time) and restart my application date and time format in mentioned column should be changed also.
On client side in XAML I have:
<resCtrl:ExtendedDataGridTextColumn Width="130" ElementStyle="{StaticResource columnStyle}" Header="{Binding Path=Resources.App_RECORD_DATE_TIME, Source={StaticResource LocalizedStrings} }" HorizontalAlignment="Left" VerticalAlignment="Center" Binding="{Binding Path=RecordDateTime, Converter={StaticResource DateTimeConverter}, UpdateSourceTrigger=PropertyChanged}"/>
Converter looks like:
public class DateTimeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null || ((DateTime)value) == new DateTime())
{
return " - ";
}
else
{
return ((DateTime)value).ToLocalTime().ToString();
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value;
}
}
And all that WORKS on client side. When I change format in windows, format is updated in table. But I have another datagrid, which has column that shows some text which contains date. So on server side, i prepare date and send only string to the client.
But on server side, I can't get system format for date - no matter what I set in control panel. Code is absolutely same, but doesn't work.
string text = someDate.ToLocalTime().ToString() + " dsfdsfds";
I tried something with CultureInfo and formats, but I can't predefine any format because I want system format - not some predefined. Do you have any solution?