diff --git a/samples/ControlCatalog.iOS/ControlCatalog.iOS.csproj b/samples/ControlCatalog.iOS/ControlCatalog.iOS.csproj
index 74d5b2fd8c..b4dac5399c 100644
--- a/samples/ControlCatalog.iOS/ControlCatalog.iOS.csproj
+++ b/samples/ControlCatalog.iOS/ControlCatalog.iOS.csproj
@@ -3,7 +3,7 @@
Exe
manual
net6.0-ios
- 10.0
+ 13.0
True
iossimulator-x64
@@ -16,4 +16,4 @@
-
\ No newline at end of file
+
diff --git a/samples/ControlCatalog.iOS/Info.plist b/samples/ControlCatalog.iOS/Info.plist
index 6ffe3ba662..1dd4416c28 100644
--- a/samples/ControlCatalog.iOS/Info.plist
+++ b/samples/ControlCatalog.iOS/Info.plist
@@ -13,7 +13,7 @@
LSRequiresIPhoneOS
MinimumOSVersion
- 10.0
+ 13.0
UIDeviceFamily
1
@@ -39,9 +39,5 @@
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
- UIStatusBarHidden
-
- UIViewControllerBasedStatusBarAppearance
-
diff --git a/samples/ControlCatalog/App.xaml.cs b/samples/ControlCatalog/App.xaml.cs
index d71d51f068..246fe4385f 100644
--- a/samples/ControlCatalog/App.xaml.cs
+++ b/samples/ControlCatalog/App.xaml.cs
@@ -44,11 +44,11 @@ namespace ControlCatalog
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
- desktopLifetime.MainWindow = new MainWindow();
+ desktopLifetime.MainWindow = new MainWindow { DataContext = new MainWindowViewModel() };
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewLifetime)
{
- singleViewLifetime.MainView = new MainView();
+ singleViewLifetime.MainView = new MainView { DataContext = new MainWindowViewModel() };
}
base.OnFrameworkInitializationCompleted();
diff --git a/samples/ControlCatalog/MainView.xaml.cs b/samples/ControlCatalog/MainView.xaml.cs
index 6f31d22677..f29da3126f 100644
--- a/samples/ControlCatalog/MainView.xaml.cs
+++ b/samples/ControlCatalog/MainView.xaml.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections;
+using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
@@ -12,6 +13,7 @@ using Avalonia.VisualTree;
using Avalonia.Styling;
using ControlCatalog.Models;
using ControlCatalog.Pages;
+using ControlCatalog.ViewModels;
namespace ControlCatalog
{
@@ -99,13 +101,47 @@ namespace ControlCatalog
};
}
+ internal MainWindowViewModel ViewModel => (MainWindowViewModel)DataContext!;
+
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
+
var decorations = this.Get("Decorations");
if (VisualRoot is Window window)
decorations.SelectedIndex = (int)window.SystemDecorations;
-
+
+ var insets = TopLevel.GetTopLevel(this)!.InsetsManager;
+ if (insets != null)
+ {
+ // In real life application these events should be unsubscribed to avoid memory leaks.
+ ViewModel.SafeAreaPadding = insets.SafeAreaPadding;
+ insets.SafeAreaChanged += (sender, args) =>
+ {
+ ViewModel.SafeAreaPadding = insets.SafeAreaPadding;
+ };
+
+ ViewModel.DisplayEdgeToEdge = insets.DisplayEdgeToEdge;
+ ViewModel.IsSystemBarVisible = insets.IsSystemBarVisible ?? false;
+
+ ViewModel.PropertyChanged += async (sender, args) =>
+ {
+ if (args.PropertyName == nameof(ViewModel.DisplayEdgeToEdge))
+ {
+ insets.DisplayEdgeToEdge = ViewModel.DisplayEdgeToEdge;
+ }
+ else if (args.PropertyName == nameof(ViewModel.IsSystemBarVisible))
+ {
+ insets.IsSystemBarVisible = ViewModel.IsSystemBarVisible;
+ }
+
+ // Give the OS some time to apply new values and refresh the view model.
+ await Task.Delay(100);
+ ViewModel.DisplayEdgeToEdge = insets.DisplayEdgeToEdge;
+ ViewModel.IsSystemBarVisible = insets.IsSystemBarVisible ?? false;
+ };
+ }
+
_platformSettings.ColorValuesChanged += PlatformSettingsOnColorValuesChanged;
PlatformSettingsOnColorValuesChanged(_platformSettings, _platformSettings.GetColorValues());
}
diff --git a/samples/ControlCatalog/MainWindow.xaml.cs b/samples/ControlCatalog/MainWindow.xaml.cs
index c589f41442..10ff94d25c 100644
--- a/samples/ControlCatalog/MainWindow.xaml.cs
+++ b/samples/ControlCatalog/MainWindow.xaml.cs
@@ -17,7 +17,6 @@ namespace ControlCatalog
{
this.InitializeComponent();
- DataContext = new MainWindowViewModel();
_recentMenu = ((NativeMenu.GetMenu(this)?.Items[0] as NativeMenuItem)?.Menu?.Items[2] as NativeMenuItem)?.Menu;
}
diff --git a/samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml b/samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml
index d690058b27..bcc1a71243 100644
--- a/samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml
+++ b/samples/ControlCatalog/Pages/WindowCustomizationsPage.xaml
@@ -5,11 +5,21 @@
xmlns:viewModels="using:ControlCatalog.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="ControlCatalog.Pages.WindowCustomizationsPage"
- x:DataType="viewModels:MainWindowViewModel">
-
-
-
-
-
+ x:DataType="viewModels:MainWindowViewModel"
+ x:CompileBindings="True">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
index 3628a9b8a7..8c6f0a2bd6 100644
--- a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
+++ b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs
@@ -6,6 +6,7 @@ using Avalonia.Platform;
using Avalonia.Reactive;
using System;
using System.ComponentModel.DataAnnotations;
+using Avalonia;
using MiniMvvm;
namespace ControlCatalog.ViewModels
@@ -20,6 +21,9 @@ namespace ControlCatalog.ViewModels
private bool _systemTitleBarEnabled;
private bool _preferSystemChromeEnabled;
private double _titleBarHeight;
+ private bool _isSystemBarVisible;
+ private bool _displayEdgeToEdge;
+ private Thickness _safeAreaPadding;
public MainWindowViewModel()
{
@@ -78,25 +82,25 @@ namespace ControlCatalog.ViewModels
{
get { return _chromeHints; }
set { this.RaiseAndSetIfChanged(ref _chromeHints, value); }
- }
+ }
public bool ExtendClientAreaEnabled
{
get { return _extendClientAreaEnabled; }
set { this.RaiseAndSetIfChanged(ref _extendClientAreaEnabled, value); }
- }
+ }
public bool SystemTitleBarEnabled
{
get { return _systemTitleBarEnabled; }
set { this.RaiseAndSetIfChanged(ref _systemTitleBarEnabled, value); }
- }
+ }
public bool PreferSystemChromeEnabled
{
get { return _preferSystemChromeEnabled; }
set { this.RaiseAndSetIfChanged(ref _preferSystemChromeEnabled, value); }
- }
+ }
public double TitleBarHeight
{
@@ -122,6 +126,24 @@ namespace ControlCatalog.ViewModels
set { this.RaiseAndSetIfChanged(ref _isMenuItemChecked, value); }
}
+ public bool IsSystemBarVisible
+ {
+ get { return _isSystemBarVisible; }
+ set { this.RaiseAndSetIfChanged(ref _isSystemBarVisible, value); }
+ }
+
+ public bool DisplayEdgeToEdge
+ {
+ get { return _displayEdgeToEdge; }
+ set { this.RaiseAndSetIfChanged(ref _displayEdgeToEdge, value); }
+ }
+
+ public Thickness SafeAreaPadding
+ {
+ get { return _safeAreaPadding; }
+ set { this.RaiseAndSetIfChanged(ref _safeAreaPadding, value); }
+ }
+
public MiniCommand AboutCommand { get; }
public MiniCommand ExitCommand { get; }