Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeConverter unavailable in Maui?

So I was trying to create a TypeConverter in Maui. And apparently, the methods aren't virtual anymore. How do I convert this Xamarin Forms code to Maui?

Also TypeConversion seems to be missing altogether, Tried to find any MS documentation on this, Well nothing there either, I am going through their Github right now for clues as to what's the right way to do this now with Maui, But for the time being, I am adding this here so someone who has a clue could guide me too,

[TypeConversion(typeof(BaseAnimation))]
public class BaseAnimationTypeConverter : TypeConverter
{
    public override object ConvertFromInvariantString(string value)
    {
        var type = (AnimationTypes)Enum.Parse(typeof(AnimationTypes), value);
        return new DefaultAnimationExtension() { Source = type }.ProvideValue(null);
    }
}
like image 929
FreakyAli Avatar asked Oct 31 '25 07:10

FreakyAli


1 Answers

Not 100% sure what it was for Xamarin, we might have had our own type because of reasons. But for .NET MAUI we're using the TypeConverter class that is in the .NET framework. So the one that's in System.ComponentModel.

If you add using System.ComponentModel; in the top of your class here it should work.

You can see a working example in the .NET MAUI Community Toolkit MediaElement here: https://github.com/CommunityToolkit/Maui/blob/main/src/CommunityToolkit.Maui.MediaElement/MediaSource/MediaSource.shared.cs#L9

like image 173
Gerald Versluis Avatar answered Nov 03 '25 01:11

Gerald Versluis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!