Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register images and set Compat Service Provider #1306

Merged
merged 5 commits into from
Jun 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/Compatibility/Core/src/AppHostBuilderExtensions.Controls.cs
Original file line number Diff line number Diff line change
@@ -218,28 +218,46 @@ static IAppHostBuilder SetupDefaults(this IAppHostBuilder builder)
DependencyService.Register<Deserializer>();
DependencyService.Register<ResourcesProvider>();
DependencyService.Register<Xaml.ValueConverterProvider>();

// Shimmed renderers go directly to the registrar to load Image Handlers
Internals.Registrar.Registered.Register(typeof(FileImageSource), typeof(FileImageSourceHandler));
Internals.Registrar.Registered.Register(typeof(StreamImageSource), typeof(StreamImagesourceHandler));
Internals.Registrar.Registered.Register(typeof(UriImageSource), typeof(ImageLoaderSourceHandler));
Internals.Registrar.Registered.Register(typeof(FontImageSource), typeof(FontImageSourceHandler));


Internals.Registrar.Registered.Register(typeof(Microsoft.Maui.EmbeddedFont), typeof(Microsoft.Maui.EmbeddedFontLoader));

#endif

#if __IOS__ || MACCATALYST
Internals.Registrar.RegisterEffect("Xamarin", "ShadowEffect", typeof(ShadowEffect));
#endif
})
.ConfigureServices(ConfigureNativeServices);
.ConfigureServices<MauiCompatBuilder>();


return builder;
}

static void ConfigureNativeServices(HostBuilderContext arg1, IServiceCollection arg2)
class MauiCompatBuilder : IMauiServiceBuilder
{
#if WINDOWS
if (!UI.Xaml.Application.Current.Resources.ContainsKey("MauiControlsPageControlStyle"))
public void Configure(HostBuilderContext context, IServiceProvider services)
{
var myResourceDictionary = new Microsoft.UI.Xaml.ResourceDictionary();
myResourceDictionary.Source = new Uri("ms-appx:///Microsoft.Maui.Controls/Platform/Windows/Styles/Resources.xbf");
Microsoft.UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
CompatServiceProvider.SetServiceProvider(services);
}

public void ConfigureServices(HostBuilderContext context, IServiceCollection services)
{
#if WINDOWS
if (!UI.Xaml.Application.Current.Resources.ContainsKey("MauiControlsPageControlStyle"))
{
var myResourceDictionary = new Microsoft.UI.Xaml.ResourceDictionary();
myResourceDictionary.Source = new Uri("ms-appx:///Microsoft.Maui.Controls/Platform/Windows/Styles/Resources.xbf");
Microsoft.UI.Xaml.Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
}
#endif
}
}
}
}