Skip to content

Commit

Permalink
Minor Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AathifMahir committed May 3, 2024
1 parent 2af724b commit 1b01c99
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/MauiIcons.Core/Extensions/BaseIconExtension2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace MauiIcons.Core;

public abstract class BaseIconExtension2<TEnum> : BindableObject, IMarkupExtension where TEnum : struct
public abstract class BaseIconExtension2<TEnum> : BindableObject, IMarkupExtension where TEnum : Enum
{
public static readonly BindableProperty IconProperty = BindableProperty.Create(nameof(Icon), typeof(TEnum?), typeof(BaseIconExtension2<TEnum>), null);
public static readonly BindableProperty IconSizeProperty = BindableProperty.Create(nameof(IconSize), typeof(double), typeof(BaseIconExtension2<TEnum>), 30.0);
Expand Down Expand Up @@ -67,7 +67,10 @@ public object ProvideValue(IServiceProvider serviceProvider)

object AssignIconsBasedOnType(object targetObject, Type? returnType)
{
if (returnType == typeof(Enum) || returnType == typeof(string))
if(returnType == typeof(Enum))
return AssignFontProperties(targetObject, disableConverter: true);

if (returnType == typeof(string))
return AssignFontProperties(targetObject);

if (returnType == typeof(ImageSource) || returnType == typeof(FontImageSource))
Expand All @@ -90,7 +93,7 @@ object AssignIconsBasedOnType(object targetObject, Type? returnType)
throw new MauiIconsExpection($"MauiIcons extension does not provide {returnType} support");
}

Binding AssignFontProperties(object targetObject)
Binding AssignFontProperties(object targetObject, bool disableConverter = false)
{
switch (targetObject)
{
Expand Down Expand Up @@ -151,7 +154,8 @@ Binding AssignFontProperties(object targetObject)
default:
throw new MauiIconsExpection($"MauiIcons extension doesn't support this control {targetObject}");
}
return new Binding(nameof(Icon), mode: BindingMode.OneWay, converter: new EnumToStringConverter(), source: this);
return disableConverter ? new Binding(nameof(Icon), mode: BindingMode.OneWay, source: this) :
new Binding(nameof(Icon), mode: BindingMode.OneWay, converter: new EnumToStringConverter(), source: this);
}
FontImageSource AssignImageSource()
{
Expand Down

0 comments on commit 1b01c99

Please sign in to comment.