예제 #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Xamarin.Forms.Forms.Init();
            BlazorHybridWindows.Init();

            // create a Xamarin Forms ContentPage container
            var xfContentPage = new Xamarin.Forms.ContentPage();

            // add MBB Hybrid Blazor/Xamarin components as-needed to that container
            _host.AddComponent <Main>(parent: xfContentPage);

            // optional, create a vanilla WPF container of some sort (here, a Grid)
            var grid = new System.Windows.Controls.Grid();

            // create a top-level vanilla WPF window, with the Grid as it's content
            var window = new Window {
                Content = grid
            };

            // add the Xamarin container to the WPF grid (can safely add other WPF elements to the grid as well)
            grid.Children.Add(xfContentPage.ToFrameworkElement());

            // show the top-level vanilla WPF window
            window.Show();
        }
예제 #2
0
        public App(IFileProvider fileProvider = null)
        {
            IHostBuilder hostBuilder = MobileBlazorBindingsHost.CreateDefaultBuilder()
                                       .ConfigureServices((hostContext, services) =>
            {
                // Adds web-specific services such as NavigationManager
                services.AddBlazorHybrid();

                // Register app-specific services
                services.AddSingleton <TodosState>();

                services.AddScoped(sp => new HttpClient {
                    BaseAddress = new Uri("https://jsonplaceholder.typicode.com/")
                });
            })
                                       .UseWebRoot("wwwroot");

            if (fileProvider != null)
            {
                hostBuilder.UseStaticFiles(fileProvider);
            }
            else
            {
                hostBuilder.UseStaticFiles();
            }
            IHost host = hostBuilder.Build();

            MainPage = new ContentPage {
                Title = GlobalConstants.AppName
            };
            host.AddComponent <Main>(parent: MainPage);
        }
예제 #3
0
파일: App.cs 프로젝트: DanGould/Hara
        public App(IFileProvider fileProvider = null, Action <IServiceCollection> configureDI = null)
        {
            var hostBuilder = MobileBlazorBindingsHost.CreateDefaultBuilder()
                              .ConfigureServices((hostContext, services) =>
            {
                // Adds web-specific services such as NavigationManager
                services.AddBlazorHybrid();

                // Register app-specific services
                services.AddSingleton <ICounterState, CounterState>();
                services.AddSingleton <ILocalContentFetcher, FileProviderLocalContentFetcher>();
                services.AddSingleton <IWebsiteLauncher, XamarinEssentialsWebsiteLauncher>();
                services.AddSingleton <IWeatherForecastFetcher, WeatherForecastFetcher>();
                services.AddSingleton <IConfigProvider, XamarinEssentialsConfigProvider>();
                configureDI?.Invoke(services);
            })
                              .UseWebRoot("wwwroot");

            if (fileProvider != null)
            {
                hostBuilder.UseStaticFiles(fileProvider);
            }
            else
            {
                hostBuilder.UseStaticFiles();
            }

            _host = hostBuilder.Build();

            MainPage = new ContentPage {
                Title = "My Application"
            };
            _host.AddComponent <Main>(parent: MainPage);
        }
예제 #4
0
        public App()
        {
            AppHost = Host.CreateDefaultBuilder()
                      .ConfigureServices((hostContext, services) =>
            {
                // Register app-specific services
                //services.AddSingleton<AppState>();
            })
                      .Build();

            AppHost.AddComponent <AppShell>(parent: this);
        }
예제 #5
0
        public App()
        {
            _host = MobileBlazorBindingsHost.CreateDefaultBuilder()
                    .ConfigureServices((hostContext, services) =>
            {
                ConfigureServices(services);
            })
                    .Build();

            MainPage = new ContentPage();
            _host.AddComponent <ShellPage>(parent: this);
        }
예제 #6
0
        public App()
        {
            AppHost = MobileBlazorBindingsHost.CreateDefaultBuilder()
                      .ConfigureServices((hostContext, services) =>
            {
                // Register app-specific services
                services.AddSingleton <WeatherService>();
            })
                      .Build();

            MainPage = new ContentPage();
            AppHost.AddComponent <MainPage>(parent: MainPage);
        }
예제 #7
0
        public App()
        {
            AppHost = MobileBlazorBindingsHost.CreateDefaultBuilder()
                      .ConfigureServices((hostContext, services) =>
            {
                // Register app-specific services
                //services.AddSingleton<AppState>();
                services.AddSingleton <ShellNavigationManager>();
            })
                      .Build();

            MainPage = new ContentPage();
            AppHost.AddComponent <AppShell>(parent: this);
        }
예제 #8
0
        public BlazorApp(IFileProvider fileProvider = null, Action <IServiceCollection> configureDI = null)
        {
            var hostBuilder = MobileBlazorBindingsHost.CreateDefaultBuilder()
                              .ConfigureServices((hostContext, services) =>
            {
                services.AddCommonServices();
                services.AddUIServices();

                // Adds web-specific services such as NavigationManager
                services.AddBlazorHybrid();

                services.AddScoped <IClipboard, XamarinClipboard>();
                services.AddSingleton <IDataDirProvider, XamarinDataDirProvider>();
                services.AddSingleton <IMainThreadInvoker, XamarinMainThreadInvoker>();
                services.AddSingleton <IShare, XamarinShare>();
                services.AddSingleton <IThemeManager, XamarinThemeManager>();

                configureDI?.Invoke(services);
            })
                              .UseWebRoot("wwwroot");

            if (fileProvider != null)
            {
                hostBuilder.UseStaticFiles(fileProvider);
            }
            else
            {
                hostBuilder.UseStaticFiles();
            }

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

            _host    = hostBuilder.Build();
            MainPage = new ContentPage {
                Title = "Chaincase"
            };
            _host.AddComponent <Main>(parent: MainPage);

            var dataDir = ServiceProvider.GetRequiredService <IDataDirProvider>().Get();

            Directory.CreateDirectory(dataDir);
            var config = ServiceProvider.GetRequiredService <Config>();

            config.LoadOrCreateDefaultFile();
            var uiConfig = ServiceProvider.GetRequiredService <UiConfig>();

            uiConfig.LoadOrCreateDefaultFile();
        }
예제 #9
0
        public App()
        {
            AppHost = MobileBlazorBindingsHost.CreateDefaultBuilder()
                      .ConfigureServices((hostContext, services) =>
            {
                // Register app-specific services
                //services.AddSingleton<AppState>();
            })
                      .Build();

            //We have to set a placeholder MainPage here, because setting it in AddComponent happens after it returns.
            //This causes iOS to kill the app because iOS thinks we never set a page.
            MainPage = new ContentPage();

            AppHost.AddComponent <AppShell>(parent: this);
        }
예제 #10
0
        public App(IServiceCollection additionalServices)
        {
            AppHost = Host.CreateDefaultBuilder()
                      .ConfigureServices((hostContext, services) =>
            {
                // Register app-specific services
                if (additionalServices != null)
                {
                    services.AddAdditionalServices(additionalServices);
                }
                //Register app-specific services
                services.AddSingleton <AppState>();
            })
                      .Build();

            AppHost.AddComponent <ToDoApp>(parent: this);
        }
예제 #11
0
        public App(IServiceCollection additionalServices)
        {
            AppHost = MobileBlazorBindingsHost.CreateDefaultBuilder()
                      .ConfigureServices((hostContext, services) =>
            {
                if (additionalServices != null)
                {
                    services.AddAdditionalServices(additionalServices);
                }

                // Register app-specific services
                services.AddSingleton <AppState>();
            })
                      .Build();

            MainPage = new TabbedPage();
            AppHost.AddComponent <TodoApp>(parent: MainPage);
        }
예제 #12
0
        public BlazorApp(IFileProvider fileProvider = null, Action <IServiceCollection> configureDI = null)
        {
            var hostBuilder = MobileBlazorBindingsHost.CreateDefaultBuilder()
                              .ConfigureServices((hostContext, services) =>
            {
                // Adds web-specific services such as NavigationManager
                services.AddBlazorHybrid();

                services.AddSingleton <IDataDirProvider, XamarinDataDirProvider>();
                services.AddSingleton <IMainThreadInvoker, XamarinMainThreadInvoker>();
                services.AddSingleton <IShare, XamarinShare>();

                configureDI?.Invoke(services);

                services.AddUIServices();
            })
                              .UseWebRoot("wwwroot");

            if (fileProvider != null)
            {
                hostBuilder.UseStaticFiles(fileProvider);
            }
            else
            {
                hostBuilder.UseStaticFiles();
            }

            _host = hostBuilder.Build();


            MainPage = new ContentPage {
                Title = "Chaincase"
            };

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

            _host.AddComponent <Main>(parent: MainPage);
        }
예제 #13
0
        public App(IServiceCollection additionalServices)
        {
            AppHost = Host.CreateDefaultBuilder()
                      .ConfigureServices((hostContext, services) =>
            {
                // Register backend-specific services (e.g. iOS, Android)
                if (additionalServices != null)
                {
                    services.AddAdditionalServices(additionalServices);
                }

                // Register app-specific services
                services.AddSingleton <AppState>();
            })

                      .ConfigureLogging(d =>
            {
                d.ClearProviders();
                d.AddConsole();
            })
                      .Build();

            AppHost.AddComponent <TodoApp>(parent: this);
        }