-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17919 from unoplatform/dev/mazi/window-unload
- Loading branch information
Showing
33 changed files
with
567 additions
and
199 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/AppWindowClosing.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Page | ||
x:Class="UITests.Microsoft_UI_Windowing.AppWindowClosing" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="using:UITests.Microsoft_UI_Windowing" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="using:Microsoft.UI.Xaml.Controls" | ||
x:DefaultBindMode="TwoWay" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" | ||
mc:Ignorable="d"> | ||
|
||
<StackPanel Padding="8" Spacing="8"> | ||
<TextBlock Text="This target platform supports multiple windows" x:Name="LogTextBlock" /> | ||
<Button x:Name="OpenWindowButton" Content="Open secondary Window" Click="OnOpenWindow" /> | ||
</StackPanel> | ||
</Page> |
70 changes: 70 additions & 0 deletions
70
src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/AppWindowClosing.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.UI.Windowing; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using SamplesApp; | ||
using Uno.Disposables; | ||
using Uno.UI.Common; | ||
using Uno.UI.Samples.Controls; | ||
using Uno.UI.Samples.UITests.Helpers; | ||
using Windows.Graphics; | ||
|
||
#if !WINDOWS_UWP && !WINAPPSDK | ||
using Uno.UI.Xaml; | ||
using Uno.UI.Xaml.Controls; | ||
using WinUICoreServices = Uno.UI.Xaml.Core.CoreServices; | ||
#endif | ||
|
||
namespace UITests.Microsoft_UI_Windowing; | ||
|
||
[Sample( | ||
"Windowing", | ||
IsManualTest = true, | ||
Description = | ||
"Click the button to open a secondary window. " + | ||
"Try to close it via title bar close button - a dialog should appear and window will remain open. " + | ||
"Close it via the 'Close' button - no dialog should appear.")] | ||
public sealed partial class AppWindowClosing : Page | ||
{ | ||
public AppWindowClosing() | ||
{ | ||
this.InitializeComponent(); | ||
if (!SupportsMultipleWindows) | ||
{ | ||
LogTextBlock.Text = "This platform does not support multiple windows."; | ||
OpenWindowButton.IsEnabled = false; | ||
} | ||
} | ||
|
||
private bool SupportsMultipleWindows => | ||
#if HAS_UNO | ||
NativeWindowFactory.SupportsMultipleWindows; | ||
#else | ||
true; | ||
#endif | ||
|
||
private void OnOpenWindow(object sender, RoutedEventArgs args) | ||
{ | ||
var secondaryWindow = new Window(); | ||
var content = new Border(); | ||
content.Child = new Button { Content = "Close", Command = new DelegateCommand(() => secondaryWindow.Close()), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; | ||
secondaryWindow.Content = content; | ||
secondaryWindow.AppWindow.Closing += OnSecondaryWindowClosing; | ||
secondaryWindow.Activate(); | ||
|
||
async void OnSecondaryWindowClosing(AppWindow sender, AppWindowClosingEventArgs args) | ||
{ | ||
args.Cancel = true; | ||
var dialog = new ContentDialog | ||
{ | ||
Title = "Closing the window canceled.", | ||
Content = "The secondary window should remain open.", | ||
CloseButtonText = "OK", | ||
XamlRoot = content.XamlRoot, | ||
}; | ||
|
||
await dialog.ShowAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/Multiwindow/WindowClosed.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Window | ||
x:Class="Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls.WindowClosed" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:App70" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
Closed="Window_Closed" | ||
Title="Test title" | ||
mc:Ignorable="d"> | ||
|
||
<Border Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" /> | ||
</Window> |
31 changes: 31 additions & 0 deletions
31
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Controls/Multiwindow/WindowClosed.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml.Controls; | ||
|
||
public sealed partial class WindowClosed : Window | ||
{ | ||
public WindowClosed() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
internal bool ClosedExecuted { get; private set; } | ||
|
||
private void Window_Closed(object sender, WindowEventArgs args) | ||
{ | ||
ClosedExecuted = true; | ||
} | ||
} |
Oops, something went wrong.