diff --git a/samples/IntegrationTestApp/App.axaml.cs b/samples/IntegrationTestApp/App.axaml.cs
index 022931366d..ed1eecb263 100644
--- a/samples/IntegrationTestApp/App.axaml.cs
+++ b/samples/IntegrationTestApp/App.axaml.cs
@@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
+using MiniMvvm;
namespace IntegrationTestApp
{
diff --git a/samples/IntegrationTestApp/IntegrationTestApp.csproj b/samples/IntegrationTestApp/IntegrationTestApp.csproj
index 77bfa828a7..82a9d87b0a 100644
--- a/samples/IntegrationTestApp/IntegrationTestApp.csproj
+++ b/samples/IntegrationTestApp/IntegrationTestApp.csproj
@@ -27,6 +27,9 @@
+
+
+
diff --git a/samples/IntegrationTestApp/MainWindow.axaml b/samples/IntegrationTestApp/MainWindow.axaml
index 29a8a254e5..3f6d507866 100644
--- a/samples/IntegrationTestApp/MainWindow.axaml
+++ b/samples/IntegrationTestApp/MainWindow.axaml
@@ -2,13 +2,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:integrationTestApp="using:IntegrationTestApp"
+ xmlns:vm="using:IntegrationTestApp.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="IntegrationTestApp.MainWindow"
Name="MainWindow"
Icon="/Assets/icon.ico"
Title="IntegrationTestApp"
- x:DataType="integrationTestApp:MainWindow">
+ x:DataType="vm:MainWindowViewModel">
@@ -19,7 +19,7 @@
-
+
@@ -28,185 +28,25 @@
WindowState:
-
+
-
-
-
-
- TextBlockWithName
-
- TextBlockWithNameAndAutomationId
-
- Label for TextBox
-
- Foo
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sample RadioButton
-
- Three States: Option 1
- Three States: Option 2
-
-
-
-
-
-
- Unchecked
- Checked
- ThreeState
-
-
-
-
-
-
- Item 0
- Item 1
-
- Wrap Selection
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- None
-
-
-
-
-
-
-
-
-
-
-
- NonOwned
- Owned
- Modal
-
-
- Manual
- CenterScreen
- CenterOwner
-
-
- Normal
- Minimized
- Maximized
- FullScreen
-
-
- None
- BorderOnly
- Full
-
- ExtendClientAreaToDecorationsHint
- Can Resize
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/IntegrationTestApp/MainWindow.axaml.cs b/samples/IntegrationTestApp/MainWindow.axaml.cs
index 986eb920a3..62ef970aa1 100644
--- a/samples/IntegrationTestApp/MainWindow.axaml.cs
+++ b/samples/IntegrationTestApp/MainWindow.axaml.cs
@@ -1,17 +1,8 @@
using System.Collections.Generic;
-using System.Linq;
-using Avalonia;
-using Avalonia.Automation;
using Avalonia.Controls;
-using Avalonia.Controls.ApplicationLifetimes;
-using Avalonia.Controls.Primitives;
-using Avalonia.Controls.Primitives.PopupPositioning;
-using Avalonia.Input;
-using Avalonia.Interactivity;
-using Avalonia.Markup.Xaml;
-using Avalonia.Media;
-using Avalonia.VisualTree;
-using Microsoft.CodeAnalysis;
+using IntegrationTestApp.Models;
+using IntegrationTestApp.Pages;
+using IntegrationTestApp.ViewModels;
namespace IntegrationTestApp
{
@@ -20,270 +11,67 @@ namespace IntegrationTestApp
public MainWindow()
{
InitializeComponent();
- InitializeViewMenu();
- InitializeGesturesTab();
- this.AttachDevTools();
- var overlayPopups = this.Get("AppOverlayPopups");
- overlayPopups.Text = Program.OverlayPopups ? "Overlay Popups" : "Native Popups";
+ var viewModel = new MainWindowViewModel(CreatePages());
+ InitializeViewMenu(viewModel.Pages);
- AddHandler(Button.ClickEvent, OnButtonClick);
- ListBoxItems = Enumerable.Range(0, 100).Select(x => "Item " + x).ToList();
- DataContext = this;
+ DataContext = viewModel;
+ AppOverlayPopups.Text = Program.OverlayPopups ? "Overlay Popups" : "Native Popups";
}
- public List ListBoxItems { get; }
+ private MainWindowViewModel? ViewModel => (MainWindowViewModel?)DataContext;
- private void InitializeComponent()
- {
- AvaloniaXamlLoader.Load(this);
- }
-
- private void InitializeViewMenu()
+ private void InitializeViewMenu(IEnumerable pages)
{
var mainTabs = this.Get("MainTabs");
var viewMenu = (NativeMenuItem?)NativeMenu.GetMenu(this)?.Items[1];
- foreach (var tabItem in mainTabs.Items.Cast())
+ foreach (var page in pages)
{
var menuItem = new NativeMenuItem
{
- Header = (string?)tabItem.Header,
- ToolTip = $"Tip:{(string?)tabItem.Header}",
- IsChecked = tabItem.IsSelected,
+ Header = (string?)page.Name,
+ ToolTip = $"Tip:{(string?)page.Name}",
ToggleType = NativeMenuItemToggleType.Radio,
};
- menuItem.Click += (_, _) => tabItem.IsSelected = true;
- viewMenu?.Menu?.Items.Add(menuItem);
- }
- }
-
- private void ShowWindow()
- {
- var sizeTextBox = this.GetControl("ShowWindowSize");
- var modeComboBox = this.GetControl("ShowWindowMode");
- var locationComboBox = this.GetControl("ShowWindowLocation");
- var stateComboBox = this.GetControl("ShowWindowState");
- var size = !string.IsNullOrWhiteSpace(sizeTextBox.Text) ? Size.Parse(sizeTextBox.Text) : (Size?)null;
- var systemDecorations = this.GetControl("ShowWindowSystemDecorations");
- var extendClientArea = this.GetControl("ShowWindowExtendClientAreaToDecorationsHint");
- var canResizeCheckBox = this.GetControl("ShowWindowCanResize");
- var owner = (Window)this.GetVisualRoot()!;
-
- var window = new ShowWindowTest
- {
- WindowStartupLocation = (WindowStartupLocation)locationComboBox.SelectedIndex,
- CanResize = canResizeCheckBox.IsChecked ?? false,
- };
-
- if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
- {
- // Make sure the windows have unique names and AutomationIds.
- var existing = lifetime.Windows.OfType().Count();
- if (existing > 0)
+ menuItem.Click += (_, _) =>
{
- AutomationProperties.SetAutomationId(window, window.Name + (existing + 1));
- window.Title += $" {existing + 1}";
- }
- }
-
- if (size.HasValue)
- {
- window.Width = size.Value.Width;
- window.Height = size.Value.Height;
- }
-
- sizeTextBox.Text = string.Empty;
- window.ExtendClientAreaToDecorationsHint = extendClientArea.IsChecked ?? false;
- window.SystemDecorations = (SystemDecorations)systemDecorations.SelectedIndex;
- window.WindowState = (WindowState)stateComboBox.SelectedIndex;
-
- switch (modeComboBox.SelectedIndex)
- {
- case 0:
- window.Show();
- break;
- case 1:
- window.Show(owner);
- break;
- case 2:
- window.ShowDialog(owner);
- break;
- }
- }
-
- private void ShowTransparentWindow()
- {
- // Show a background window to make sure the color behind the transparent window is
- // a known color (green).
- var backgroundWindow = new Window
- {
- Title = "Transparent Window Background",
- Name = "TransparentWindowBackground",
- Width = 300,
- Height = 300,
- Background = Brushes.Green,
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- };
-
- // This is the transparent window with a red circle.
- var window = new Window
- {
- Title = "Transparent Window",
- Name = "TransparentWindow",
- SystemDecorations = SystemDecorations.None,
- Background = Brushes.Transparent,
- TransparencyLevelHint = new[] { WindowTransparencyLevel.Transparent },
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- Width = 200,
- Height = 200,
- Content = new Border
- {
- Background = Brushes.Red,
- CornerRadius = new CornerRadius(100),
- }
- };
-
- window.PointerPressed += (_, _) =>
- {
- window.Close();
- backgroundWindow.Close();
- };
-
- backgroundWindow.Show(this);
- window.Show(backgroundWindow);
- }
-
- private void ShowTransparentPopup()
- {
- var popup = new Popup
- {
- WindowManagerAddShadowHint = false,
- Placement = PlacementMode.AnchorAndGravity,
- PlacementAnchor = PopupAnchor.Top,
- PlacementGravity = PopupGravity.Bottom,
- Width= 200,
- Height= 200,
- Child = new Border
- {
- Background = Brushes.Red,
- CornerRadius = new CornerRadius(100),
- }
- };
-
- // Show a background window to make sure the color behind the transparent window is
- // a known color (green).
- var backgroundWindow = new Window
- {
- Title = "Transparent Popup Background",
- Name = "TransparentPopupBackground",
- Width = 200,
- Height = 200,
- Background = Brushes.Green,
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- Content = new Border
- {
- Name = "PopupContainer",
- Child = popup,
- [AutomationProperties.AccessibilityViewProperty] = AccessibilityView.Content,
- }
- };
-
- backgroundWindow.PointerPressed += (_, _) => backgroundWindow.Close();
- backgroundWindow.Show(this);
-
- popup.Open();
- }
-
- private void SendToBack()
- {
- var lifetime = (ClassicDesktopStyleApplicationLifetime)Application.Current!.ApplicationLifetime!;
-
- foreach (var window in lifetime.Windows.ToArray())
- {
- window.Activate();
- }
- }
-
- private void RestoreAll()
- {
- var lifetime = (ClassicDesktopStyleApplicationLifetime)Application.Current!.ApplicationLifetime!;
+ if (ViewModel is { } viewModel)
+ viewModel.SelectedPage = page;
+ };
- foreach (var window in lifetime.Windows.ToArray())
- {
- window.Show();
- if (window.WindowState == WindowState.Minimized)
- window.WindowState = WindowState.Normal;
+ viewMenu?.Menu?.Items.Add(menuItem);
}
}
- private void InitializeGesturesTab()
+ private void Pager_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
- var gestureBorder = this.GetControl("GestureBorder");
- var gestureBorder2 = this.GetControl("GestureBorder2");
- var lastGesture = this.GetControl("LastGesture");
- var resetGestures = this.GetControl