protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) { DispatcherQueueSyncContext.SetForCurrentThread(); base.OnLaunched(args); m_window = new MainWindow(); WindowWrapper windowWrapper = WindowWrapper.FromAbi(m_window.ThisPtr); m_windowHandle = windowWrapper.WindowHandle; m_window.Title = "Folder Inspector (.NET Desktop WinUI 3)"; m_window.Activate(); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Invoked when the application is launched. Override this method to perform application /// initialization and to display initial content in the associated Window. /// </summary> /// /// <param name="args"> Event data for the event. </param> /// /// <seealso cref="Microsoft.UI.Xaml.Application.OnLaunched(LaunchActivatedEventArgs)"/> //////////////////////////////////////////////////////////////////////////////////////////////////// protected override void OnLaunched(LaunchActivatedEventArgs args) { //At the moment I do not know why or if this is required but I noticed it // in example code somewhere and decided to add it. DispatcherQueueSyncContext.SetForCurrentThread(); //I am not sure if calling the default is a noop. The WinUI template did not // call the base but the same example code that I spoke about above did. base.OnLaunched(args); //Create a window and set the page. var window = _serviceProvider.GetRequiredService <IExtWindow>(); //Set the initial page to display by grabbing the View Model which will cause // the DataTemplate system to display the content with a template that we // provided through the App.xaml resources. var windowVm = _serviceProvider.GetRequiredService <WindowVm>(); windowVm.ClientsContent = _serviceProvider.GetRequiredService <MainPageVm>(); window.Vm = windowVm; //Start transparent so we have a chance to resize before its visible. This does not // fully satisfy my desire to show a Window with a specific size without the need // for WinUI to show it at a random size first. More work will come on this, but this // is a rough half-baked work-around until I can get to this area. window.SetTransparency(100); window.Activate(); //This will have a jarring effect because I have not had time to figure out how to set the size before // the window is activated for the first time. window.Resize(600, 400); //Make the window fully visible by removing the transparency. window.SetTransparency(0); }
private static void Main(string[] args) { ComWrappersSupport.InitializeComWrappers(); Application.Start(p => { DispatcherQueueSyncContext.SetForCurrentThread(); new App(); }); }