我尝试将DateTimeFormatCultureConverter实施到DataGridTextColumn
.
它可以工作,我可以调试它,但它根本不会改变 DateTime 格式。所以我看不到任何明显的变化......
(我总是可以使用return formated; // DateTime.Parse(formated);
但在这种情况下按 ASC/DESC 对字段进行排序不起作用。)
任何线索为什么?
谢谢!
代码
public class DateTimeFormatCultureConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
DateTime originalValue = (DateTime)value;
CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;
if (currentUICulture.EnglishName.Contains("Spanish") || currentUICulture.EnglishName.Contains("Portuguese"))
{
string formated = string.Format("{0}/{1}/{2}", originalValue.Day, originalValue.Month, originalValue.Year);
return DateTime.Parse(formated);
}
else
{
string formated = string.Format("{0}/{1}/{2}", originalValue.Month, originalValue.Day, originalValue.Year);
return DateTime.Parse(formated);
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
数据网格
<sdk:DataGridTextColumn x:Name="txcInstalled"
CanUserReorder="True"
CanUserResize="True"
CanUserSort="True"
Width="Auto"
Binding="{Binding Installed, Converter={StaticResource DateTimeFormatCultureConverter}}"
IsReadOnly="True" />