UXDivers / Gorilla-Player-Support

This is the public Gorilla Player support website
http://gorillaplayer.com
115 stars 17 forks source link

Problem with specific IValueConverter Static Resource not Found #190

Open v1rtu41m4n opened 7 years ago

v1rtu41m4n commented 7 years ago

i had a problem with a specific IValueConverter, currently I have two on my page but in only crash with one of them, I already register the types on android main activity and configure it on gorilla.json (by the way both converter are in the same assembly same namespace) but I had have not luck, any help should be appreciated.

This is the xaml with the working converter: <Grid HorizontalOptions="Fill" HeightRequest="266" IsVisible="{Binding Photo, Converter={StaticResource NullVisibilityConverter}}">

This is the xaml with the non working converter: <Label Text="{Binding TotalLikes}" VerticalOptions="Center" TextColor="{Binding IsLikeSetByProfile, Converter={StaticResource IsLikeSetByProfileColorConverter}" />

Both converters are referenced in the resource dictionary of the app.xaml: `

</Application.Resources>`

this are the converters

`public class NullVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return !string.IsNullOrEmpty((string)value); }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}`

`public class IsLikeSetByProfileColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Color color = Color.Black;

        if ((bool)value)
        {
            if (Application.Current.Resources != null)
            {
                color = (Color)Application.Current.Resources["ControlActivatedColor"]; 
            }
            else
            {
                color = Color.FromHex("#299FD6");
            }
        }
        else
        {
            if (Application.Current.Resources != null)
            {
                color = (Color)Application.Current.Resources["ControlNormalLightColor"]; 
            }
            else
            {
                color = Color.FromHex("#9C9D9F");
            }
        }

        return color;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}`
v1rtu41m4n commented 7 years ago

the error persist I the resource is defined on the same page

<converters:IsLikeSetByProfileColorConverter x:Key="IsLikeSetByProfileColorConverter" />

leemorris commented 7 years ago

I am having the same issue with IConverters as StaticResources not being found. I also have multiple RegisterAssemblyFromType statements in my MainActivity.cs, all for types that are in the same assembly. I do not have a Gorilla.json file.

This is from my App.xaml:

<?xml version="1.0" encoding="utf-8"?>
<Application xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             x:Class="MyPOC.App" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             d1p1:Ignorable="d" 
             xmlns:converter="clr-namespace:MyPOC.Helpers;assembly=MyPOCPCL"
             xmlns:local="clr-namespace:MyPOC.ViewModel;assembly=MyPOCPCL"
             xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006"
             >
    <Application.Resources>
         <!--Application resource dictionary-->
        <ResourceDictionary >
            <local:ViewModelLocator x:Key="Locator"  />
            <converter:GreaterThanZeroConverter x:Key="GreaterThanZeroConverter" />
            <converter:NotConverter x:Key="NotConverter" />
            <converter:DebugDataBindingConverter x:Key="DebugBinding" />

This is from my page

<Label Text="No Values" IsVisible="{Binding IsVisible, Converter={StaticResource GreaterThanZeroConverter}" />

This is from my MainActivity.cs:

        LoadApplication(UXDivers.Gorilla.Droid.Player.CreateApplication(
            this,
            new UXDivers.Gorilla.Config("Good Gorilla")
                          .RegisterAssemblyFromType<MyPOC.App>()
                          .RegisterAssemblyFromType<ImageCircle.Forms.Plugin.Abstractions.CircleImage>()
                          .RegisterAssemblyFromType<MyPOC.CardView>()
                          .RegisterAssemblyFromType<MyPOC.ViewModel.ViewModelLocator>()
                          .RegisterAssemblyFromType<MyPOC.Helpers.DebugDataBindingConverter>()
                          .RegisterAssemblyFromType<MyPOC.Helpers.GreaterThanZeroConverter>()
                          .RegisterAssemblyFromType<MyPOC.Helpers.NotConverter>()

            ));

The error I get in Gorilla SDK is:

"StaticResource not found for key GreaterThanZeroConverter" The detail about the error: "Error loading XAML. The reported error: Xamarin.Forms.Xaml.XamlParseException:Position 27:49 Static Resource not found for key GreaterThanZeroConverter"