Skip to content

Commit

Permalink
test: AppWindow positioning and sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 5, 2024
1 parent c543197 commit b10a94d
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 3 deletions.
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>
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace UITests.Microsoft_UI_Windowing;

[Sample("Microsoft.UI.Windowing", IsManualTest = true, ViewModelType = typeof(AppWindowPresentersViewModel),
[Sample("Windowing", IsManualTest = true, ViewModelType = typeof(AppWindowPresentersViewModel),
Description =
"Clicking the buttons should change the window presenter and the mode of the window." +
"CompactOverlay is not yet implemented in Uno Platform, so it will show an error instead.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace UITests.Microsoft_UI_Windowing;

[Sample("Microsoft.UI.Windowing", Name = "OverlappedPresenter", IsManualTest = true, ViewModelType = typeof(OverlappedPresenterTestsViewModel),
[Sample("Windowing", Name = "OverlappedPresenter", IsManualTest = true, ViewModelType = typeof(OverlappedPresenterTestsViewModel),
Description = "Playground for testing of OverlappedPresenter functionality.")]
public sealed partial class OverlappedPresenterTests : Page
{
Expand Down
9 changes: 8 additions & 1 deletion src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\AppWindowPositionAndSize.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\AppWindowPresenters.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -5456,6 +5460,9 @@
<Compile Include="$(MSBuildThisFileDirectory)MessageDialogTests\MessageDialogTest.xaml.cs">
<DependentUpon>MessageDialogTest.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\AppWindowPositionAndSize.xaml.cs">
<DependentUpon>AppWindowPositionAndSize.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Windowing\AppWindowPresenters.xaml.cs">
<DependentUpon>AppWindowPresenters.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -9780,4 +9787,4 @@
</Compile>
</ItemGroup>
<Import Project="ItemExclusions.props" />
</Project>
</Project>
17 changes: 17 additions & 0 deletions src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Uno.Foundation.Logging;
using Windows.Foundation;
using Windows.UI.Core;
using Windows.Graphics;
using Microsoft.UI.Dispatching;

namespace Uno.UI.Xaml.Controls;

Expand Down Expand Up @@ -128,6 +130,16 @@ public virtual string Title
}
}

public bool IsVisible => throw new NotImplementedException();

public PointInt32 Position => throw new NotImplementedException();

public SizeInt32 Size => throw new NotImplementedException();

public SizeInt32 ClientSize => throw new NotImplementedException();

public DispatcherQueue DispatcherQueue => throw new NotImplementedException();

public event EventHandler<Size>? SizeChanged;
public event EventHandler<Rect>? VisibleBoundsChanged;
public event EventHandler<CoreWindowActivationState>? ActivationChanged;
Expand Down Expand Up @@ -190,4 +202,9 @@ private void RaiseContentIslandStateChanged(ContentIslandStateChangedEventArgs a
{
XamlRoot?.VisualTree.ContentRoot.CompositionContent?.RaiseStateChanged(args);
}
public void Destroy() => throw new NotImplementedException();
public void Hide() => throw new NotImplementedException();
public void Move(PointInt32 position) => throw new NotImplementedException();
public void Resize(SizeInt32 size) => throw new NotImplementedException();
public void Show(bool activateWindow) => throw new NotImplementedException();
}

0 comments on commit b10a94d

Please sign in to comment.