1
1
// // Copyright (c) Microsoft. All rights reserved.
2
2
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
3
4
+ using Microsoft . UI ;
5
+ using Microsoft . UI . Windowing ;
4
6
using System ;
5
7
using System . Globalization ;
6
8
using System . Windows ;
7
9
using System . Windows . Controls ;
8
10
using System . Windows . Input ;
11
+ using System . Windows . Interop ;
12
+ using Windows . ApplicationModel . Contacts ;
9
13
10
14
namespace CalculatorDemo
11
15
{
@@ -18,6 +22,7 @@ public sealed partial class MainWindow : Window
18
22
private Operation _lastOper ;
19
23
private string _lastVal ;
20
24
private string _memVal ;
25
+ private AppWindow _appWindow ;
21
26
22
27
public MainWindow ( )
23
28
{
@@ -444,5 +449,45 @@ public void Clear()
444
449
_args = string . Empty ;
445
450
}
446
451
}
452
+
453
+ private void CompactView_Click ( object sender , RoutedEventArgs e )
454
+ {
455
+ SetCompactView ( true ) ;
456
+ }
457
+
458
+ private void ExitCompactViewButton_Click ( object sender , RoutedEventArgs e )
459
+ {
460
+ SetCompactView ( false ) ;
461
+ }
462
+
463
+ void SetCompactView ( bool useCompactView )
464
+ {
465
+ // Ensure we have an AppWindow for this WPF Window.
466
+ if ( _appWindow == null )
467
+ {
468
+ _appWindow = AppWindow . GetFromWindowId (
469
+ new WindowId ( ( ulong ) new WindowInteropHelper ( this ) . Handle ) ) ;
470
+ }
471
+
472
+ if ( useCompactView )
473
+ {
474
+ // For compact view, hide the main panel and show the compact panel.
475
+ MyPanel . Visibility = Visibility . Collapsed ;
476
+ CompactPanel . Visibility = Visibility . Visible ;
477
+
478
+ CompactViewText . Text = DisplayBox . Text ;
479
+
480
+ // The AppWindow's CompactOverlay mode will make it always-on-top.
481
+ _appWindow . SetPresenter ( AppWindowPresenterKind . CompactOverlay ) ;
482
+ _appWindow . ResizeClient ( new Windows . Graphics . SizeInt32 ( 300 , 80 ) ) ;
483
+ }
484
+ else
485
+ {
486
+ MyPanel . Visibility = Visibility . Visible ;
487
+ CompactPanel . Visibility = Visibility . Collapsed ;
488
+
489
+ _appWindow . SetPresenter ( AppWindowPresenterKind . Default ) ;
490
+ }
491
+ }
447
492
}
448
493
}
0 commit comments