You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to create a IValueConverter which converts a given DateTime in UTC to a local time.
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is not DateTime dt)
{
throw new InvalidOperationException("The target must be a DateTime");
}
return dt.ToLocalTime();
}
If you use this converter it will throw an Error that cannot cast a System.DateTime object to a System.String object.
You need to return a value that is of type string in order to work. Like this: return dt.ToLocalTime().ToString(CultureInfo.CurrentCulture)
As per my logic, when I pass an object of a specific type in the converter, it should also be possible to return the same object type.
Steps to reproduce the bug
Create a IValueConverter which converts a given DateTime in UTC to a local time.
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is not DateTime dt)
{
throw new InvalidOperationException("The target must be a DateTime");
}
return dt.ToLocalTime();
}
Expected behavior
No response
Screenshots
No response
NuGet package version
None
Windows version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered:
Describe the bug
I want to create a
IValueConverter
which converts a given DateTime in UTC to a local time.If you use this converter it will throw an Error that cannot cast a System.DateTime object to a System.String object.
You need to return a value that is of type string in order to work. Like this:
return dt.ToLocalTime().ToString(CultureInfo.CurrentCulture)
As per my logic, when I pass an object of a specific type in the converter, it should also be possible to return the same object type.
Steps to reproduce the bug
Create a
IValueConverter
which converts a given DateTime in UTC to a local time.Expected behavior
No response
Screenshots
No response
NuGet package version
None
Windows version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: