static void Main(string[] args) { var application = new Application(); Forms.Init(); var formsApplicationPage = new FormsApplicationPage(); formsApplicationPage.LoadApplication(new App()); application.Run(formsApplicationPage); }
static void Main(string[] args) { var application = new Application(); Forms.Init(); var formsApplicationPage = new FormsApplicationPage(); formsApplicationPage.LoadApplication(new XamarinNeller.App()); Task.Run(() => { Task.Delay(1000).Wait(); application.Dispatcher.InvokeAsync(() => { var window = new Window() { Height = 600, Width = 600 }; var viewPage = new ViewPage() { HeightRequest = 500, WidthRequest = 500 }; var pageRenderer = new PageRenderer(); var mainPage = new MainPage(); pageRenderer.SetElement(viewPage); //var formsContentLoader = new FormsContentLoader(); //var content = formsContentLoader.LoadContentAsync(window,null, mainPage,new CancellationToken()).Result; var frameworkElement = pageRenderer.GetNativeElement(); window.Content = frameworkElement; window.Show(); }); }); application.Run(); }
/// <summary> /// Toggles the window between visible and hidden. /// </summary> private void ToggleWindow() { // Create window when it is opened for the first time if (MainWindow == null) { MainWindow = new FormsApplicationPage { Title = "Bounce UDP", Height = 400, Width = 400, Topmost = true, ShowInTaskbar = false, ResizeMode = ResizeMode.NoResize, WindowStyle = WindowStyle.ToolWindow }; ((FormsApplicationPage)MainWindow).LoadApplication(new Shared.App()); MainWindow.Closing += MainWindow_Closing; Application.Current.SendStart(); } // Hide the window when it is visible if (MainWindow.IsVisible) { // Hide! MainWindow.Deactivated -= MainWindowOnDeactivated; MainWindow.Hide(); Application.Current.SendSleep(); } // Show the window when it is not visible else { // Position window var position = GetPosition(); MainWindow.Left = position.X; MainWindow.Top = position.Y; // Show! MainWindow.Show(); MainWindow.Activate(); MainWindow.Deactivated += MainWindowOnDeactivated; Application.Current.SendResume(); } }
/// <summary> /// Toggles the window between visible and hidden. /// </summary> private void ToggleWindow() { // Create window when it is opened for the first time if (MainWindow == null) { MainWindow = new FormsApplicationPage { Title = "Xamarin.Forms tray!", Height = 600, Width = 350, Topmost = true, ShowInTaskbar = false, ResizeMode = ResizeMode.NoResize, WindowStyle = WindowStyle.ToolWindow }; ((FormsApplicationPage)MainWindow).LoadApplication(new Shared.App()); MainWindow.Closing += MainWindow_Closing; Application.Current.SendStart(); } // Hide the window when it is visible if (MainWindow.IsVisible) { // Hide! MainWindow.Deactivated -= MainWindowOnDeactivated; MainWindow.Hide(); Application.Current.SendSleep(); } // Show the window when it is not visible else { // Position window MainWindow.Left = SystemParameters.WorkArea.Width - MainWindow.Width - 50; MainWindow.Top = SystemParameters.WorkArea.Height - MainWindow.Height - 50; // Show! MainWindow.Show(); MainWindow.Activate(); MainWindow.Deactivated += MainWindowOnDeactivated; Application.Current.SendResume(); } }
// Called when the app needs to initialize protected override void OnStartup(StartupEventArgs e) { // Init Xamarin.Forms Forms.Init(); base.OnStartup(e); // create icon trayIcon = new NotifyIcon(); trayIcon.MouseUp += NotifyIconOnMouseUp; trayIcon.MouseMove += NotifyIconOnMouseMove; // listen for theme changes SystemEvents.UserPreferenceChanging += (obj, evnt) => UpdateTrayIcon(); // create context menu trayIcon.ContextMenuStrip = new ContextMenuStrip(); trayIcon.ContextMenuStrip.Items.Add("Quit").Click += (s, eArg) => Applicaton_Quit(); // create window Core.PreferencesProvider.Default = new WinPreferencesProvider(); MainWindow = new FormsApplicationPage { Title = "WizLightUniversal", Height = 540, Width = 400, Topmost = true, ShowInTaskbar = false, ResizeMode = ResizeMode.NoResize, WindowStyle = WindowStyle.None }; ((FormsApplicationPage)MainWindow).LoadApplication(new Core.App()); MainWindow.Deactivated += MainWindow_Deactivated; // enable tray icon and start app UpdateTrayIcon(); IsQuitting = false; }
public static Control ToControl(this Page view) { if (!Forms.IsInitialized) { throw new InvalidOperationException("Call Forms.Init() before this"); } if (!(view.RealParent is Application)) { Application app = new DefaultApplication { MainPage = view }; var formsApplicationPage = new FormsApplicationPage(); formsApplicationPage.LoadApplication(app); var platform = new Platform(formsApplicationPage); platform.SetPage(view); } IVisualElementRenderer renderer = Platform.GetOrCreateRenderer(view); if (renderer == null) { throw new InvalidOperationException($"Could not find or create a renderer for {view}"); } var Control = renderer.GetNativeElement(); Control.AttachedToLogicalTree += (sender, e) => { view.Layout(new Rectangle(0, 0, Control.Bounds.Width, Control.Bounds.Height)); }; return(Control); }
public static FrameworkElement ToFrameworkElement(this Page view) { if (!System.Maui.Maui.IsInitialized) { throw new InvalidOperationException("Call System.Maui.Maui.Init() before this"); } if (!(view.RealParent is Application)) { Application app = new DefaultApplication { MainPage = view }; var formsApplicationPage = new FormsApplicationPage(); formsApplicationPage.LoadApplication(app); var platform = new Platform(formsApplicationPage); platform.SetPage(view); } IVisualElementRenderer renderer = Platform.GetOrCreateRenderer(view); if (renderer == null) { throw new InvalidOperationException($"Could not find or create a renderer for {view}"); } var frameworkElement = renderer.GetNativeElement(); frameworkElement.Loaded += (sender, args) => { view.Layout(new Rectangle(0, 0, frameworkElement.ActualWidth, frameworkElement.ActualHeight)); }; return(frameworkElement); }