Ejemplo n.º 1
0
        public object ProvideValue(IServiceProvider serviceProvider)
        {
            ImageSource result = null;

            if (Source != null)
            {
                IResourceLocator resLocator = Mvx.IoCProvider.Resolve <IResourceLocator>();

                if (resLocator == null || resLocator.ResourcesAssembly == null || !resLocator.HasPath(ResourceKeys.ImagesKey))
                {
                    Debug.WriteLine("Resource info not set for images");
                }
                else
                {
                    string resourceFullName = resLocator.GetResourcePath(ResourceKeys.ImagesKey, Source);

#if DEBUG
                    string[] assemblyResourceNames = resLocator.ResourcesAssembly.GetManifestResourceNames();

                    if (!assemblyResourceNames.Contains(resourceFullName))
                    {
                        Debug.WriteLine($"Trying to bind image from resource {resourceFullName}, but it wasn't found in asembly {resLocator.ResourcesAssembly.FullName}");
                    }
#endif

                    try
                    {
                        result = ImageSource.FromResource(resourceFullName, resLocator.ResourcesAssembly);
                    }
                    catch (Exception)
                    {
                        // Simply return null for unfound resources
                    }
                }
            }

            return(result);
        }