Skip to content

Commit 38ccb7e

Browse files
committed
Split demos into different partial files
1 parent 9c03c97 commit 38ccb7e

File tree

6 files changed

+126
-90
lines changed

6 files changed

+126
-90
lines changed
Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
// // Copyright (c) Microsoft. All rights reserved.
2-
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
#if true // Demo3_Step1_AddWasdk
5-
using Microsoft.UI.Dispatching;
6-
#endif
74
using System.Windows;
85

96
namespace CalculatorDemo
@@ -13,24 +10,6 @@ namespace CalculatorDemo
1310
/// </summary>
1411
public partial class App : Application
1512
{
16-
#if true // Demo3_Step1_AddWasdk
17-
// Many WinAppSDK APIs require a DispatcherQueue to be running on the thread. We'll start one when the app starts up
18-
// and shut it down when the app is finished.
19-
protected override void OnStartup(StartupEventArgs e)
20-
{
21-
_dispatcherQueueController = DispatcherQueueController.CreateOnCurrentThread();
22-
base.OnStartup(e);
23-
}
2413

25-
protected override void OnExit(ExitEventArgs e)
26-
{
27-
base.OnExit(e);
28-
_dispatcherQueueController?.ShutdownQueue();
29-
_dispatcherQueueController = null;
30-
}
31-
32-
DispatcherQueueController? _dispatcherQueueController;
33-
#endif
3414
}
35-
36-
}
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// // Copyright (c) Microsoft. All rights reserved.
2+
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Windows;
5+
6+
#if true // Demo3_Step1_AddWasdk
7+
8+
using Microsoft.UI.Dispatching;
9+
10+
namespace CalculatorDemo
11+
{
12+
public partial class App : Application
13+
{
14+
// Many WinAppSDK APIs require a DispatcherQueue to be running on the thread. We'll start one when the app starts up
15+
// and shut it down when the app is finished.
16+
protected override void OnStartup(StartupEventArgs e)
17+
{
18+
_dispatcherQueueController = DispatcherQueueController.CreateOnCurrentThread();
19+
base.OnStartup(e);
20+
}
21+
22+
protected override void OnExit(ExitEventArgs e)
23+
{
24+
base.OnExit(e);
25+
_dispatcherQueueController?.ShutdownQueue();
26+
_dispatcherQueueController = null;
27+
}
28+
29+
DispatcherQueueController? _dispatcherQueueController;
30+
}
31+
}
32+
33+
#endif

Samples/Islands/WpfCalculator/CalculatorDemo/CalculatorDemo.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<!-- WinAppSDK requires at least the 17763 build of windows, so we need to set that here.
44
You can set this in the Visual Studio project properties UI too. -->
@@ -96,10 +96,13 @@
9696
<DependentUpon>App.xaml</DependentUpon>
9797
<SubType>Code</SubType>
9898
</Compile>
99+
<Compile Include="App_Demo3.cs" />
99100
<Compile Include="MainWindow.cs">
100101
<DependentUpon>MainWindow.xaml</DependentUpon>
101102
<SubType>Code</SubType>
102103
</Compile>
104+
<Compile Include="MainWindow_Demo3.cs" />
105+
<Compile Include="MainWindow_Demo4.cs" />
103106
</ItemGroup>
104107
<ItemGroup>
105108
<Compile Include="MyTextBox.cs" />

Samples/Islands/WpfCalculator/CalculatorDemo/MainWindow.cs

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
using System.Windows.Input;
99
using System.Windows.Interop;
1010
using Windows.ApplicationModel.Contacts;
11-
#if true // Demo3_Step2_AddCompact
12-
using Microsoft.UI;
13-
using Microsoft.UI.Windowing;
14-
#endif
1511

1612
namespace CalculatorDemo
1713
{
@@ -24,13 +20,6 @@ public sealed partial class MainWindow : Window
2420
private Operation _lastOper;
2521
private string _lastVal;
2622
private string _memVal;
27-
#if true // Demo3_Step2_AddCompact
28-
private AppWindow _appWindow;
29-
#endif
30-
31-
#if true // Demo4_Step2_AddIsland
32-
private Microsoft.UI.Composition.Compositor _compositor = new Microsoft.UI.Composition.Compositor();
33-
#endif
3423
public MainWindow()
3524
{
3625
InitializeComponent();
@@ -456,59 +445,5 @@ public void Clear()
456445
_args = string.Empty;
457446
}
458447
}
459-
460-
#if true // Demo3_Step2_AddCompact
461-
private void CompactView_Click(object sender, RoutedEventArgs e)
462-
{
463-
SetCompactView(true);
464-
}
465-
466-
private void ExitCompactViewButton_Click(object sender, RoutedEventArgs e)
467-
{
468-
SetCompactView(false);
469-
}
470-
471-
void SetCompactView(bool useCompactView)
472-
{
473-
// Ensure we have an AppWindow for this WPF Window.
474-
if (_appWindow == null)
475-
{
476-
_appWindow = AppWindow.GetFromWindowId(
477-
new WindowId((ulong)new WindowInteropHelper(this).Handle));
478-
}
479-
480-
if (useCompactView)
481-
{
482-
// For compact view, hide the main panel and show the compact panel.
483-
MyPanel.Visibility = Visibility.Collapsed;
484-
CompactPanel.Visibility = Visibility.Visible;
485-
486-
CompactViewText.Text = DisplayBox.Text;
487-
488-
// The AppWindow's CompactOverlay mode will make it always-on-top.
489-
_appWindow.SetPresenter(AppWindowPresenterKind.CompactOverlay);
490-
}
491-
else
492-
{
493-
MyPanel.Visibility = Visibility.Visible;
494-
CompactPanel.Visibility = Visibility.Collapsed;
495-
496-
_appWindow.SetPresenter(AppWindowPresenterKind.Default);
497-
}
498-
}
499-
#endif
500-
501-
#if true // Demo4_Step2_AddIsland
502-
private void CreateDrawingIslandMenuItem_Click(object sender, RoutedEventArgs e)
503-
{
504-
var wpfIslandHost = new WpfIslandHost(_compositor);
505-
var drawingIsland = new DrawingIslandComponents.DrawingIsland(_compositor);
506-
507-
// After this, the WpfIslandHost will be live, and the DesktopChildSiteBridge will be available.
508-
DisplayAreaBorder.Child = wpfIslandHost;
509-
510-
wpfIslandHost.DesktopChildSiteBridge.Connect(drawingIsland.Island);
511-
}
512-
#endif
513448
}
514449
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// // Copyright (c) Microsoft. All rights reserved.
2+
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Windows;
6+
using System.Windows.Interop;
7+
8+
#if true // Demo3_Step2_AddCompact
9+
10+
using Microsoft.UI;
11+
using Microsoft.UI.Windowing;
12+
13+
namespace CalculatorDemo
14+
{
15+
public sealed partial class MainWindow : Window
16+
{
17+
private AppWindow _appWindow;
18+
19+
private void CompactView_Click(object sender, RoutedEventArgs e)
20+
{
21+
SetCompactView(true);
22+
}
23+
24+
private void ExitCompactViewButton_Click(object sender, RoutedEventArgs e)
25+
{
26+
SetCompactView(false);
27+
}
28+
29+
void SetCompactView(bool useCompactView)
30+
{
31+
// Ensure we have an AppWindow for this WPF Window.
32+
if (_appWindow == null)
33+
{
34+
_appWindow = AppWindow.GetFromWindowId(
35+
new WindowId((ulong)new WindowInteropHelper(this).Handle));
36+
}
37+
38+
if (useCompactView)
39+
{
40+
// For compact view, hide the main panel and show the compact panel.
41+
MyPanel.Visibility = Visibility.Collapsed;
42+
CompactPanel.Visibility = Visibility.Visible;
43+
44+
CompactViewText.Text = DisplayBox.Text;
45+
46+
// The AppWindow's CompactOverlay mode will make it always-on-top.
47+
_appWindow.SetPresenter(AppWindowPresenterKind.CompactOverlay);
48+
}
49+
else
50+
{
51+
MyPanel.Visibility = Visibility.Visible;
52+
CompactPanel.Visibility = Visibility.Collapsed;
53+
54+
_appWindow.SetPresenter(AppWindowPresenterKind.Default);
55+
}
56+
}
57+
}
58+
}
59+
60+
#endif
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// // Copyright (c) Microsoft. All rights reserved.
2+
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Windows;
5+
6+
#if true // Demo3_Step2_AddCompact
7+
8+
namespace CalculatorDemo
9+
{
10+
public sealed partial class MainWindow : Window
11+
{
12+
private Microsoft.UI.Composition.Compositor _compositor = new Microsoft.UI.Composition.Compositor();
13+
private void CreateDrawingIslandMenuItem_Click(object sender, RoutedEventArgs e)
14+
{
15+
var wpfIslandHost = new WpfIslandHost(_compositor);
16+
var drawingIsland = new DrawingIslandComponents.DrawingIsland(_compositor);
17+
18+
// After this, the WpfIslandHost will be live, and the DesktopChildSiteBridge will be available.
19+
DisplayAreaBorder.Child = wpfIslandHost;
20+
21+
wpfIslandHost.DesktopChildSiteBridge.Connect(drawingIsland.Island);
22+
}
23+
}
24+
}
25+
26+
#endif

0 commit comments

Comments
 (0)