I have a WPF applciation, one of functionality is convert the date acoording to the CultureInfo.
the cultureinfo.Culture by defalult in my applciation is "en-GB".
And I use the element FrameworkElement : so the "en-US" is the default cultureinfo.Culture.
I change it at the runtime with this line in my code:
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name)));
In this case , the cultureinfo.Culture in the FrameworkElement is changed successuffly to "en-GB"
and I test in debugging (in the immediate command in visual studio) :
DateTime date;
if (DateTime.TryParse("05/27/2021", out date);
and the result is FALSE! ( it is OK) Also :
DateTime date;
if (DateTime.TryParse("30/05/2021", out date);
and the result is TRUE! ( it is OK)
But the problem in fact I get the date from an external excel file, and I get the date from this file without any problem, but unfortunately always I have the result for this : "not a valid date" that is to say it takes the "en-US" format!!
I don't understand how it make this?!
this is the essential part of my code:
public override DataTemplate SelectTemplate(object item,
DependencyObject container)
{
DataTemplate template = null;
if (item != null)
{
var objectType = (item as IEnumerable<object>).FirstOrDefault();
if (objectType != null)
{
FrameworkElement element = container as FrameworkElement;
and the object item contains the list of dates from my excel file.
Thanks