35
loading...
This website collects cookies to deliver better user experience
using Windows.UI.Xaml.Controls;
using UnoSample.ViewModels;
namespace UnoSample
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.Loaded += (sender, e) => Console.WriteLine("Loaddeded");
this.InitializeComponent();
this.DataContext = new MainPageViewModel();
}
}
}
using GLib;
using Uno.UI.Runtime.Skia;
using UnoSample.Skia.Gtk.MotionControllers;
namespace UnoSample.Skia.Gtk
{
class Program
{
static void Main(string[] args)
{
// I also can use "using statement"
using(var motionController = new MotionController())
{
ExceptionManager.UnhandledException += delegate (UnhandledExceptionArgs expArgs)
{
expArgs.ExitApplication = true;
};
var host = new GtkHost(() => new App(), args);
host.Run();
// execute closing operations.
}
}
}
}
...
namespace UnoSample
{
public sealed partial class App : Application
{
private Window _window;
public void Greet(string message)
{
Console.WriteLine($"SharedApp {message}");
}
...
...
class Program
{
static void Main(string[] args)
{
using(var motionController = new MotionController())
{
...
var host = new GtkHost(() => new App(), args);
host.Run();
// Because I can't get instances by "App.Current" before executing "host.Run()",
// I can only execute closing operations from Program.cs.
((App)App.Current).Greet("Call from Gtk");
}
}
}
}
using GLib;
using Microsoft.Extensions.DependencyInjection;
using Uno.UI.Runtime.Skia;
using UnoSample.ViewModels;
namespace UnoSample.Skia.Gtk
{
class Program
{
static void Main(string[] args)
{
var servicesProvider = BuildDi(args);
using (servicesProvider as IDisposable)
{
...
var host = new GtkHost(() => new App(servicesProvider), args);
host.Run();
}
}
private static IServiceProvider BuildDi(string[] args)
{
var services = new ServiceCollection();
services.AddScoped<MainPageViewModel>();
return services.BuildServiceProvider();
}
}
}
...
namespace UnoSample
{
public sealed partial class App : Application
{
private Window? _window;
public IServiceProvider ServiceProvider { get; }
public App(IServiceProvider serviceProvider)
{
this.ServiceProvider = serviceProvider;
InitializeLogging();
this.InitializeComponent();
...
using Windows.UI.Xaml.Controls;
using UnoSample.ViewModels;
namespace UnoSample
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.DataContext = ((App)App.Current).ServiceProvider.GetService(typeof(MainPageViewModel));
}
}
}