예제 #1
0
파일: Startup.cs 프로젝트: sattew/maui
 public void Configure(IAppHostBuilder appBuilder)
 {
     appBuilder
     .RegisterCompatibilityForms()
     .RegisterCompatibilityRenderers()
     .UseMauiApp <App>();
 }
예제 #2
0
        public static IAppHostBuilder RegisterCompatibilityRenderers(this IAppHostBuilder builder)
        {
            // This won't really be a thing once we have all the handlers built
            var defaultHandlers = new List <Type>
            {
                typeof(Button),
                typeof(Editor),
                typeof(Entry),
                typeof(ContentPage),
                typeof(Page),
                typeof(Label),
                typeof(Slider),
                typeof(Stepper),
                typeof(Switch),
                typeof(SearchBar)
            };

            Forms.RegisterCompatRenderers(
                new[] { typeof(RendererToHandlerShim).Assembly },
                typeof(RendererToHandlerShim).Assembly,
                (controlType) =>
            {
                foreach (var type in defaultHandlers)
                {
                    if (type.IsAssignableFrom(controlType))
                    {
                        return;
                    }
                }

                builder.RegisterHandler(controlType, typeof(RendererToHandlerShim));
            });

            return(builder);
        }
예제 #3
0
 public void Configure(IAppHostBuilder appBuilder)
 {
     appBuilder
     .ConfigureServices(this.BuildServiceCollection)
     .UseFormsCompatibility()
     .UseMauiApp <LamuneApplication>();
 }
예제 #4
0
        public static IAppHostBuilder UseFormsCompatibility(this IAppHostBuilder builder, bool registerRenderers = true)
        {
            // TODO: this hideousness is just until the dynamic handler registration is merged
            FormsCompatBuilder?     compatBuilder      = null;
            IMauiHandlersCollection?handlersCollection = null;

            builder.ConfigureMauiHandlers(handlers =>
            {
                handlersCollection = handlers;
                compatBuilder?.SetHandlersCollection(handlersCollection);
            });

            builder.ConfigureServices <FormsCompatBuilder>(compat =>
            {
                // TODO: this hideousness is just until the dynamic handler registration is merged
                compatBuilder = compat;
                if (handlersCollection != null)
                {
                    compatBuilder.SetHandlersCollection(handlersCollection);
                }

                compat.UseCompatibilityRenderers = registerRenderers;
            });

            return(builder);
        }
예제 #5
0
 public static IAppHostBuilder UsePlugins <TPlugin>(
     this IAppHostBuilder appHostBuilder,
     WebHostBuilderContext context,
     IApplicationBuilder appBuilder,
     IPluginHost plugins)
     where TPlugin : class, IConfigureWebAppPlugin
 => appHostBuilder.UsePlugins(context, appBuilder, plugins.GetPlugins <TPlugin>());
        public static IAppHostBuilder ConfigureIconFonts(this IAppHostBuilder builder, Action <FontOptionsBuilder> configureOptions)
        {
            LabelHandler.LabelMapper[KnownPropertyNames.Icon] = (handler, view) =>
            {
                if (view is not Label label)
                {
                    return;
                }

                var selector = (string)label.GetValue(FontIcon.IconProperty);
                (var glyph, string fontName) = Lookup(selector, handler.MauiContext);
                label.Text       = glyph;
                label.FontFamily = fontName;
            };

            ButtonHandler.ButtonMapper[KnownPropertyNames.Icon] = (handler, view) =>
            {
                if (view is not Button button)
                {
                    return;
                }

                var selector = (string)button.GetValue(FontIcon.IconProperty);
                (var glyph, string fontName) = Lookup(selector, handler.MauiContext);
                button.Text       = glyph;
                button.FontFamily = fontName;
            };

            ImageHandler.ImageMapper[KnownPropertyNames.Icon]  = ImageMapper;
            ImageHandler.ImageMapper[KnownPropertyNames.Color] = ImageMapper;
            ImageHandler.ImageMapper[KnownPropertyNames.Size]  = ImageMapper;

            return(builder.ConfigureIconFontsInternal(configureOptions));
        }
예제 #7
0
        public static IAppHostBuilder ConfigureIconFonts(this IAppHostBuilder builder, Action <FontOptionsBuilder> configureOptions)
        {
            LabelHandler.LabelMapper[KnownPropertyNames.Icon] = (handler, view) =>
            {
                if (view is not Text text)
                {
                    return;
                }

                var selector = (string)text.GetEnvironment(KnownPropertyNames.Icon, cascades: false);
                (var glyph, string fontName) = Lookup(selector, handler.MauiContext);
                text.SetEnvironment("Text", glyph, cascades: false);
                text.SetEnvironment("Font", Font.OfSize(fontName, view.Font.FontSize), cascades: false);
            };

            ButtonHandler.ButtonMapper[KnownPropertyNames.Icon] = (handler, view) =>
            {
                if (view is not Button button)
                {
                    return;
                }

                var selector = (string)button.GetEnvironment(KnownPropertyNames.Icon, cascades: false);
                (var glyph, string fontName) = Lookup(selector, handler.MauiContext);
                button.SetEnvironment("Text", glyph, cascades: false);
                button.SetEnvironment("Font", Font.OfSize(fontName, view.Font.FontSize), cascades: false);
            };

            ImageHandler.ImageMapper[KnownPropertyNames.Icon]  = ImageMapper;
            ImageHandler.ImageMapper[KnownPropertyNames.Color] = ImageMapper;
            ImageHandler.ImageMapper[KnownPropertyNames.Size]  = ImageMapper;

            return(builder.ConfigureIconFontsInternal(configureOptions));
        }
예제 #8
0
        public static IAppHostBuilder ConfigureIconFontsInternal(this IAppHostBuilder builder, Action <FontOptionsBuilder> configureOptions)
        {
            var options = new FontOptionsBuilder();

            configureOptions(options);
            builder.ConfigureServices(x =>
            {
                x.AddSingleton <IFontRegistry, FontRegistryImplementation>();
                foreach (var font in options.Fonts)
                {
                    x.AddSingleton <IFont>(font);
                }
            });

            builder.ConfigureFonts(fc =>
            {
                foreach (var font in options.Fonts)
                {
                    fc.AddEmeddedResourceFont(font.GetType().Assembly, font.FontFileName, font.Alias);
                }
            });

            builder.ConfigureImageSources((issc) =>
            {
                issc.AddService <IIconImageSource, IconImageSourceService>();
            });

            return(builder);
        }
예제 #9
0
 public void Configure(IAppHostBuilder appBuilder)
 {
     appBuilder
     .UseFormsCompatibility()
     .RegisterBlazorMauiWebView()
     .UseMauiApp <MyApp>();
 }
예제 #10
0
        //new ListView<int>(Enumerable.Range(0,1000).ToList())
        //{
        //	ViewFor = (i) =>  new Text($"Cell: {i}"),

        //};
        //	new VStack(spacing: 6)
        //	{
        //		new Text("Welcome to Comet!!!!").Margin(top: 100).Color(Colors.Blue),
        //		// new Image("turtlerock.jpg").Frame(100,100),
        //		new ShapeView(new Circle().Stroke(Colors.Fuchsia,2)
        //			.Fill(new RadialGradient(new Color[] { Colors.LightGray, Colors.Black}, new Point(.5, .25), 0, 100)))
        //			.Frame(100,100).Padding(2).Background(Colors.White),
        //		new ShapeView(new Shapes.Rectangle().Stroke(Colors.Fuchsia,2)
        //			.Fill(new LinearGradient(new Color[] { Colors.LightGray, Colors.Black}, new Point(0, 0), new Point(1,1))))
        //		.Frame(100,100).Padding(10).Background(Colors.White),
        //		new ShapeView(new Ellipse().Stroke(Colors.Fuchsia,2).Fill(Colors.Blue)).Frame(100,100).Padding(2).Background(Colors.White),
        //		new Text(() => !isToggled ?  "Off" : "Hey I am toggled"),
        //		new Button(()=>  $"I was Clicked: {clickCount}!!!!!",()=>{
        //			clickCount.Value++;
        //		}).Color(Colors.Yellow)
        //			.Background(Colors.Blue),
        //		new ActivityIndicator(),
        //		new CheckBox(isToggled),
        //		new Toggle(isToggled),
        //		new TextEditor(textValue),
        //		new ProgressBar(progress),
        //		new Slider(progress),
        //		new Text(textValue),
        //		new TextField(textValue),
        //		new SecureField(textValue),
        //}.Background(Colors.Beige);

        public override void Configure(IAppHostBuilder appBuilder)
        {
            base.Configure(appBuilder);
#if DEBUG
            appBuilder.EnableHotReload();
#endif
        }
예제 #11
0
        public static IAppHostBuilder RegisterHandler <TType, TTypeRender>(this IAppHostBuilder builder)
            where TType : IFrameworkElement
            where TTypeRender : IViewHandler
        {
            builder.ConfigureHandlers((context, handlersCollection) => handlersCollection.AddTransient(typeof(TType), typeof(TTypeRender)));

            return(builder);
        }
예제 #12
0
 public virtual void Configure(IAppHostBuilder appBuilder)
 {
     appBuilder.ConfigureServices((context, collection) => {
         collection.AddSingleton <IApplication, CometApp>((s) => {
             return(CurrentApp);
         });
     });
     appBuilder.UseCometHandlers();
 }
예제 #13
0
 public static IAppHostBuilder UseMauiApp <TApp>(this IAppHostBuilder builder, Func <IServiceProvider, TApp> implementationFactory)
     where TApp : class, IApplication
 {
     builder.ConfigureServices((context, collection) =>
     {
         collection.AddSingleton <IApplication>(implementationFactory);
     });
     return(builder);
 }
예제 #14
0
 public static IAppHostBuilder UseMauiApp <TApp>(this IAppHostBuilder builder)
     where TApp : class, IApplication
 {
     builder.ConfigureServices((context, collection) =>
     {
         collection.AddSingleton <IApplication, TApp>();
     });
     return(builder);
 }
예제 #15
0
 public void Configure(IAppHostBuilder appBuilder)
 {
     appBuilder
     .UseMauiApp <App>()
     .ConfigureFonts(fonts =>
     {
         fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
     });
 }
예제 #16
0
 public NoopMiniHostPlugin(
     IPluginHost plugins,
     IAppHostBuilder appHostBuilder,
     ILogger <NoopMiniHostPlugin>?log = null)
 {
     _log            = log ??= NullLogger <NoopMiniHostPlugin> .Instance;
     Plugins         = plugins;
     MiniHostBuilder = (MiniHostBuilder)appHostBuilder;
 }
예제 #17
0
        public static IAppHostBuilder RegisterHandlers(this IAppHostBuilder builder, Dictionary <Type, Type> handlers)
        {
            foreach (var handler in handlers)
            {
                builder?.ConfigureHandlers((context, handlersCollection) => handlersCollection.AddTransient(handler.Key, handler.Value));
            }

            return(builder);
        }
예제 #18
0
 public static IAppHostBuilder EnableHotReload(this IAppHostBuilder builder, string?ideIp = null, int idePort = 9988)
 {
     builder.ConfigureServices <HotReloadBuilder>(hotReload =>
     {
         hotReload.IdeIp   = ideIp;
         hotReload.IdePort = idePort;
     });
     return(builder);
 }
예제 #19
0
        public void Configure(IAppHostBuilder appBuilder)
        {
            if (UseXamlApp)
            {
                // Use all the Forms features
                appBuilder = appBuilder
                             .UseFormsCompatibility()
                             .UseMauiApp <XamlApp>();
            }
            else
            {
                // Use just the Forms renderers
                appBuilder = appBuilder
                             .UseCompatibilityRenderers()
                             .UseMauiApp <MyApp>();
            }

            appBuilder
#if NET6_0_OR_GREATER
            .RegisterBlazorMauiWebView()
#endif
            .ConfigureAppConfiguration(config =>
            {
                config.AddInMemoryCollection(new Dictionary <string, string>
                {
                    { "MyKey", "Dictionary MyKey Value" },
                    { ":Title", "Dictionary_Title" },
                    { "Position:Name", "Dictionary_Name" },
                    { "Logging:LogLevel:Default", "Warning" }
                });
            })
            .UseMauiServiceProviderFactory(true)
            //.UseServiceProviderFactory(new DIExtensionsServiceProviderFactory())
            .ConfigureServices(services =>
            {
                services.AddSingleton <ITextService, TextService>();
                services.AddTransient <MainPageViewModel>();

                services.AddTransient(
                    serviceType: typeof(IPage),
                    implementationType: _pageType switch
                {
                    PageType.Xaml => typeof(XamlPage),
                    PageType.Semantics => typeof(SemanticsPage),
                    PageType.Blazor =>
#if NET6_0_OR_GREATER
                    typeof(BlazorPage),
#else
                    throw new NotSupportedException("Blazor requires .NET 6 or higher."),
#endif
                    PageType.Main => typeof(MainPage),
                    _ => throw new Exception(),
                });

                services.AddTransient <IWindow, MainWindow>();
            })
예제 #20
0
 public static IAppHostBuilder UseFonts(this IAppHostBuilder builder)
 {
     builder.ConfigureServices((context, collection) =>
     {
         collection.AddSingleton <IEmbeddedFontLoader, EmbeddedFontLoader>();
         collection.AddSingleton <IFontRegistrar>(provider => new FontRegistrar(provider.GetRequiredService <IEmbeddedFontLoader>()));
         collection.AddSingleton <IFontManager>(provider => new FontManager(provider.GetRequiredService <IFontRegistrar>()));
     });
     return(builder);
 }
예제 #21
0
 public void Configure(IAppHostBuilder appBuilder)
 {
     appBuilder
     .UseMauiApp <App>()
     .ConfigureFonts(fonts =>
     {
         fonts.AddFont("Lato-Bold.ttf", "LatoBold");
         fonts.AddFont("Lato-Semibold.ttf", "LatoSemiBold");
     });
 }
예제 #22
0
 public static IAppHostBuilder ConfigureImageSources(this IAppHostBuilder builder)
 {
     builder.ConfigureImageSources(services =>
     {
         services.AddService <IFileImageSource>(svcs => new FileImageSourceService(svcs.GetService <IImageSourceServiceConfiguration>(), svcs.CreateLogger <FileImageSourceService>()));
         services.AddService <IFontImageSource>(svcs => new FontImageSourceService(svcs.GetRequiredService <IFontManager>(), svcs.CreateLogger <FontImageSourceService>()));
         services.AddService <IStreamImageSource>(svcs => new StreamImageSourceService(svcs.CreateLogger <StreamImageSourceService>()));
         services.AddService <IUriImageSource>(svcs => new UriImageSourceService(svcs.CreateLogger <UriImageSourceService>()));
     });
     return(builder);
 }
 public static IAppHostBuilder UseSkiaSharpHandlers(this IAppHostBuilder builder) =>
 builder
 .ConfigureMauiHandlers(handlers =>
 {
     handlers.AddHandler <SKCanvasView, SKCanvasViewHandler>();
 })
 .ConfigureImageSources(sources =>
 {
     sources.AddService <ISKImageImageSource, SKImageSourceService>();
     sources.AddService <ISKBitmapImageSource, SKImageSourceService>();
     sources.AddService <ISKPixmapImageSource, SKImageSourceService>();
     sources.AddService <ISKPictureImageSource, SKImageSourceService>();
 });
예제 #24
0
        public static IAppHostBuilder ConfigureEssentials(this IAppHostBuilder builder, Action <IEssentialsBuilder> configureDelegate = null)
        {
            if (configureDelegate == null)
            {
                builder.ConfigureEssentials((Action <HostBuilderContext, IEssentialsBuilder>)null);
            }
            else
            {
                builder.ConfigureEssentials((_, essentials) => configureDelegate(essentials));
            }

            return(builder);
        }
예제 #25
0
        public static IAppHostBuilder UseMauiHandlers(this IAppHostBuilder builder)
        {
            builder.RegisterHandlers(new Dictionary <Type, Type>
            {
                { typeof(IButton), typeof(ButtonHandler) },
                { typeof(IEntry), typeof(EntryHandler) },
                { typeof(ILayout), typeof(LayoutHandler) },
                { typeof(ILabel), typeof(LabelHandler) },
                { typeof(ISlider), typeof(SliderHandler) },
                { typeof(ISwitch), typeof(SwitchHandler) }
            });

            return(builder);
        }
예제 #26
0
        public static IAppHostBuilder RegisterCompatibilityRenderer(
            this IAppHostBuilder builder,
            Type controlType,
            Type rendererType)
        {
            // register renderer with old registrar so it can get shimmed
            // This will move to some extension method
            Microsoft.Maui.Controls.Internals.Registrar.Registered.Register(
                controlType,
                rendererType);

            builder.RegisterHandler(controlType, typeof(RendererToHandlerShim));
            return(builder);
        }
예제 #27
0
        public static IAppHostBuilder ConfigureEssentials(this IAppHostBuilder builder, Action <HostBuilderContext, IEssentialsBuilder> configureDelegate = null)
        {
            builder.ConfigureLifecycleEvents(life =>
            {
#if __ANDROID__
                Platform.Init(MauiApplication.Current);

                life.AddAndroid(android => android
                                .OnRequestPermissionsResult((activity, requestCode, permissions, grantResults) =>
                {
                    Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
                })
                                .OnNewIntent((activity, intent) =>
                {
                    Platform.OnNewIntent(intent);
                })
                                .OnResume((activity) =>
                {
                    Platform.OnResume();
                }));
#elif __IOS__
                life.AddiOS(ios => ios
                            .ContinueUserActivity((application, userActivity, completionHandler) =>
                {
                    return(Platform.ContinueUserActivity(application, userActivity, completionHandler));
                })
                            .OpenUrl((application, url, options) =>
                {
                    return(Platform.OpenUrl(application, url, options));
                })
                            .PerformActionForShortcutItem((application, shortcutItem, completionHandler) =>
                {
                    Platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler);
                }));
#elif WINDOWS
                life.AddWindows(windows => windows
                                .OnLaunched((application, args) =>
                {
                    Platform.OnLaunched(args);
                }));
#endif
            });

            if (configureDelegate != null)
            {
                builder.ConfigureServices <EssentialsBuilder>(configureDelegate);
            }

            return(builder);
        }
예제 #28
0
        public static IAppHostBuilder UseSkiaSharpCompatibilityRenderers(this IAppHostBuilder builder) =>
        builder
        .ConfigureMauiHandlers(handlers =>
        {
            handlers.AddCompatibilityRenderer(typeof(SKCanvasView), typeof(SKCanvasViewRenderer));
#if !WINDOWS
            handlers.AddCompatibilityRenderer(typeof(SKGLView), typeof(SKGLViewRenderer));
#endif

            CompatRegistrar.Registered.Register(typeof(SKImageImageSource), typeof(SKImageSourceHandler));
            CompatRegistrar.Registered.Register(typeof(SKBitmapImageSource), typeof(SKImageSourceHandler));
            CompatRegistrar.Registered.Register(typeof(SKPixmapImageSource), typeof(SKImageSourceHandler));
            CompatRegistrar.Registered.Register(typeof(SKPictureImageSource), typeof(SKImageSourceHandler));
        });
예제 #29
0
 public void Configure(IAppHostBuilder appBuilder)
 {
     appBuilder
     .UseFormsCompatibility()
     .UseMauiApp <App>()
     .ConfigureFonts(fonts =>
     {
         fonts.AddFont("ionicons.ttf", "IonIcons");
     })
     .ConfigureMauiHandlers(handlers =>
     {
         handlers.AddHandler <RadChart, RadChartHandler>();
     });
 }
예제 #30
0
파일: Startup.cs 프로젝트: sattew/maui
        public void Configure(IAppHostBuilder appBuilder)
        {
            if (UseXamlApp)
            {
                appBuilder = appBuilder
                             .RegisterCompatibilityForms()
                             .UseMauiApp <XamlApp>();
            }
            else
            {
                appBuilder = appBuilder
                             .UseMauiApp <MyApp>();
            }

            appBuilder
            .RegisterCompatibilityRenderers()
            .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.AddInMemoryCollection(new Dictionary <string, string>
                {
                    { "MyKey", "Dictionary MyKey Value" },
                    { ":Title", "Dictionary_Title" },
                    { "Position:Name", "Dictionary_Name" },
                    { "Logging:LogLevel:Default", "Warning" }
                });
            })
            .UseMauiServiceProviderFactory(true)
            //.UseServiceProviderFactory(new DIExtensionsServiceProviderFactory())
            .ConfigureServices((hostingContext, services) =>
            {
                services.AddSingleton <ITextService, TextService>();
                services.AddTransient <MainPageViewModel>();

                if (UseXamlPage)
                {
                    services.AddTransient <IPage, XamlPage>();
                }
                else
                {
                    services.AddTransient <IPage, MainPage>();
                }

                services.AddTransient <IWindow, MainWindow>();
            })
            .ConfigureFonts((hostingContext, fonts) =>
            {
                fonts.AddFont("Dokdo-Regular.ttf", "Dokdo");
            });
        }