forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test:
AppWindow
positioning and sizing
- Loading branch information
1 parent
c543197
commit b10a94d
Showing
6 changed files
with
204 additions
and
3 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/AppWindowPositionAndSize.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,20 @@ | ||
<Page | ||
x:Class="UITests.Microsoft_UI_Windowing.AppWindowPositionAndSize" | ||
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" | ||
x:DefaultBindMode="TwoWay" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" | ||
mc:Ignorable="d"> | ||
|
||
<StackPanel Padding="8" Spacing="8"> | ||
<NumberBox Header="X" Value="{x:Bind ViewModel.X}" /> | ||
<NumberBox Header="Y" Value="{x:Bind ViewModel.Y}" /> | ||
<Button Click="{x:Bind ViewModel.Move}">Move</Button> | ||
<NumberBox Header="Width" Value="{x:Bind ViewModel.Width}" /> | ||
<NumberBox Header="Height" Value="{x:Bind ViewModel.Height}" /> | ||
<Button Click="{x:Bind ViewModel.Resize}">Resize</Button> | ||
</StackPanel> | ||
</Page> |
157 changes: 157 additions & 0 deletions
157
src/SamplesApp/UITests.Shared/Microsoft_UI_Windowing/AppWindowPositionAndSize.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,157 @@ | ||
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.Samples.Controls; | ||
using Uno.UI.Samples.UITests.Helpers; | ||
using Windows.Graphics; | ||
|
||
namespace UITests.Microsoft_UI_Windowing; | ||
|
||
[Sample( | ||
"Windowing", | ||
Name = "AppWindowPositionAndSize", | ||
IsManualTest = true, | ||
ViewModelType = typeof(AppWindowPositionAndSizeViewModel), | ||
Description = "Playground for window position and size changes.")] | ||
public sealed partial class AppWindowPositionAndSize : Page | ||
{ | ||
public AppWindowPositionAndSize() | ||
{ | ||
this.InitializeComponent(); | ||
DataContextChanged += AppWindowPositionAndSize_DataContextChanged; | ||
} | ||
|
||
internal AppWindowPositionAndSizeViewModel ViewModel { get; private set; } | ||
|
||
private void AppWindowPositionAndSize_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args) | ||
{ | ||
ViewModel = args.NewValue as AppWindowPositionAndSizeViewModel; | ||
ViewModel.XamlRoot = XamlRoot; | ||
} | ||
} | ||
|
||
internal class AppWindowPositionAndSizeViewModel : ViewModelBase | ||
{ | ||
private AppWindow _appWindow; | ||
private PointInt32 _position; | ||
private SizeInt32 _size; | ||
|
||
public AppWindowPositionAndSizeViewModel() | ||
{ | ||
_appWindow = App.MainWindow.AppWindow; | ||
|
||
_appWindow.Changed += OnAppWindowChanged; | ||
Disposables.Add(Disposable.Create(() => _appWindow.Changed -= OnAppWindowChanged)); | ||
|
||
UpdateProperties(); | ||
} | ||
|
||
private void OnAppWindowChanged(AppWindow sender, AppWindowChangedEventArgs args) => UpdateProperties(); | ||
|
||
private void UpdateProperties() | ||
{ | ||
_position = _appWindow.Position; | ||
_size = _appWindow.Size; | ||
RaisePropertyChanged(nameof(Position)); | ||
RaisePropertyChanged(nameof(Size)); | ||
RaisePropertyChanged(nameof(X)); | ||
RaisePropertyChanged(nameof(Y)); | ||
RaisePropertyChanged(nameof(Width)); | ||
RaisePropertyChanged(nameof(Height)); | ||
} | ||
|
||
internal XamlRoot XamlRoot { get; set; } | ||
|
||
internal int X | ||
{ | ||
get => _position.X; | ||
set | ||
{ | ||
if (_position.X != value) | ||
{ | ||
_position.X = value; | ||
RaisePropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
internal int Y | ||
{ | ||
get => _position.Y; | ||
set | ||
{ | ||
if (_position.Y != value) | ||
{ | ||
_position.Y = value; | ||
RaisePropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
internal PointInt32 Position => _position; | ||
|
||
internal int Width | ||
{ | ||
get => _size.Width; | ||
set | ||
{ | ||
if (_size.Width != value) | ||
{ | ||
_size.Width = value; | ||
RaisePropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
internal int Height | ||
{ | ||
get => _size.Height; | ||
set | ||
{ | ||
if (_size.Height != value) | ||
{ | ||
_size.Height = value; | ||
RaisePropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
internal SizeInt32 Size => _size; | ||
|
||
internal async void Move() | ||
{ | ||
try | ||
{ | ||
_appWindow.Move(Position); | ||
} | ||
catch (Exception ex) | ||
{ | ||
await ShowMessage(ex.Message); | ||
} | ||
} | ||
|
||
internal async void Resize() | ||
{ | ||
try | ||
{ | ||
_appWindow.Resize(Size); | ||
} | ||
catch (Exception ex) | ||
{ | ||
await ShowMessage(ex.Message); | ||
} | ||
} | ||
|
||
private async Task ShowMessage(string message) | ||
{ | ||
var contentDialog = new ContentDialog(); | ||
contentDialog.Content = message; | ||
contentDialog.XamlRoot = XamlRoot; | ||
contentDialog.PrimaryButtonText = "OK"; | ||
await contentDialog.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