Skip to content

Commit

Permalink
fix(dotnetTemplate): Fixed Window losing scope on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-welton authored and jeromelaban committed Apr 23, 2021
1 parent 4821fbe commit 0d5418d
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/SolutionTemplate/UnoSolutionTemplate/Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ namespace $ext_safeprojectname$
/// </summary>
public sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
#if NET5_0 && WINDOWS
private Window _window;

#else
private Windows.UI.Xaml.Window _window;
#endif

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
InitializeLogging();

Expand All @@ -53,13 +60,13 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
#endif

#if NET5_0 && WINDOWS
var window = new Window();
window.Activate();
_window = new Window();
_window.Activate();
#else
var window = Windows.UI.Xaml.Window.Current;
_window = Windows.UI.Xaml.Window.Current;
#endif

var rootFrame = window.Content as Frame;
var rootFrame = _window.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
Expand All @@ -76,7 +83,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
}

// Place the frame in the current Window
window.Content = rootFrame;
_window.Content = rootFrame;
}

#if !(NET5_0 && WINDOWS)
Expand All @@ -91,7 +98,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
window.Activate();
_window.Activate();
}
}

Expand Down

0 comments on commit 0d5418d

Please sign in to comment.