Skip to content

Commit 0d5418d

Browse files
luke-weltonjeromelaban
authored andcommitted
fix(dotnetTemplate): Fixed Window losing scope on Windows
1 parent 4821fbe commit 0d5418d

File tree

1 file changed

+18
-11
lines changed
  • src/SolutionTemplate/UnoSolutionTemplate/Shared

1 file changed

+18
-11
lines changed

src/SolutionTemplate/UnoSolutionTemplate/Shared/App.xaml.cs

+18-11
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ namespace $ext_safeprojectname$
2323
/// </summary>
2424
public sealed partial class App : Application
2525
{
26-
/// <summary>
27-
/// Initializes the singleton application object. This is the first line of authored code
28-
/// executed, and as such is the logical equivalent of main() or WinMain().
29-
/// </summary>
30-
public App()
26+
#if NET5_0 && WINDOWS
27+
private Window _window;
28+
29+
#else
30+
private Windows.UI.Xaml.Window _window;
31+
#endif
32+
33+
/// <summary>
34+
/// Initializes the singleton application object. This is the first line of authored code
35+
/// executed, and as such is the logical equivalent of main() or WinMain().
36+
/// </summary>
37+
public App()
3138
{
3239
InitializeLogging();
3340

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

5562
#if NET5_0 && WINDOWS
56-
var window = new Window();
57-
window.Activate();
63+
_window = new Window();
64+
_window.Activate();
5865
#else
59-
var window = Windows.UI.Xaml.Window.Current;
66+
_window = Windows.UI.Xaml.Window.Current;
6067
#endif
6168

62-
var rootFrame = window.Content as Frame;
69+
var rootFrame = _window.Content as Frame;
6370

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

7885
// Place the frame in the current Window
79-
window.Content = rootFrame;
86+
_window.Content = rootFrame;
8087
}
8188

8289
#if !(NET5_0 && WINDOWS)
@@ -91,7 +98,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
9198
rootFrame.Navigate(typeof(MainPage), e.Arguments);
9299
}
93100
// Ensure the current window is active
94-
window.Activate();
101+
_window.Activate();
95102
}
96103
}
97104

0 commit comments

Comments
 (0)