diff --git a/samples/ControlCatalog.Desktop/Program.cs b/samples/ControlCatalog.Desktop/Program.cs index eeb2095201..d555ce1399 100644 --- a/samples/ControlCatalog.Desktop/Program.cs +++ b/samples/ControlCatalog.Desktop/Program.cs @@ -33,9 +33,7 @@ namespace ControlCatalog private static void ConfigureAssetAssembly(AppBuilder builder) { - AvaloniaLocator.CurrentMutable - .GetRequiredService() - .SetDefaultAssembly(typeof(App).Assembly); + AssetLoader.SetDefaultAssembly(typeof(App).Assembly); } } } diff --git a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs index a5423fab52..b1ce10df24 100644 --- a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs @@ -468,8 +468,8 @@ CanPickFolder: {storageProvider.CanPickFolder}"; private IStorageProvider GetStorageProvider() { var forceManaged = this.Get("ForceManaged").IsChecked ?? false; - return forceManaged - ? new ManagedStorageProvider(GetWindow()) + return forceManaged + ? new ManagedStorageProvider(GetWindow()) // NOTE: In your production App use 'AppBuilder.UseManagedSystemDialogs()' : GetTopLevel().StorageProvider; } diff --git a/samples/ControlCatalog/Pages/TabControlPage.xaml.cs b/samples/ControlCatalog/Pages/TabControlPage.xaml.cs index ed48811809..269cbc763d 100644 --- a/samples/ControlCatalog/Pages/TabControlPage.xaml.cs +++ b/samples/ControlCatalog/Pages/TabControlPage.xaml.cs @@ -51,8 +51,7 @@ namespace ControlCatalog.Pages private static Bitmap LoadBitmap(string uri) { - var assets = AvaloniaLocator.Current.GetRequiredService(); - return new Bitmap(assets.Open(new Uri(uri))); + return new Bitmap(AssetLoader.Open(new Uri(uri))); } } } diff --git a/samples/ControlCatalog/ViewModels/CursorPageViewModel.cs b/samples/ControlCatalog/ViewModels/CursorPageViewModel.cs index f44d927801..dfcdd4361d 100644 --- a/samples/ControlCatalog/ViewModels/CursorPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/CursorPageViewModel.cs @@ -18,8 +18,7 @@ namespace ControlCatalog.ViewModels .Select(x => new StandardCursorModel(x)) .ToList(); - var loader = AvaloniaLocator.Current.GetRequiredService(); - var s = loader.Open(new Uri("avares://ControlCatalog/Assets/avalonia-32.png")); + var s = AssetLoader.Open(new Uri("avares://ControlCatalog/Assets/avalonia-32.png")); var bitmap = new Bitmap(s); CustomCursor = new Cursor(bitmap, new PixelPoint(16, 16)); } diff --git a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs index 9b9e336806..1050beedf2 100644 --- a/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs +++ b/samples/ControlCatalog/ViewModels/MainWindowViewModel.cs @@ -3,7 +3,6 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.Notifications; using Avalonia.Dialogs; using Avalonia.Platform; -using Avalonia.Reactive; using System; using System.ComponentModel.DataAnnotations; using Avalonia; @@ -50,28 +49,28 @@ namespace ControlCatalog.ViewModels WindowState.FullScreen, }; - this.WhenAnyValue(x => x.SystemTitleBarEnabled, x=>x.PreferSystemChromeEnabled) - .Subscribe(x => + this.PropertyChanged += (s, e) => { - var hints = ExtendClientAreaChromeHints.NoChrome | ExtendClientAreaChromeHints.OSXThickTitleBar; - - if(x.Item1) - { - hints |= ExtendClientAreaChromeHints.SystemChrome; - } - - if(x.Item2) + if (e.PropertyName is nameof(SystemTitleBarEnabled) or nameof(PreferSystemChromeEnabled)) { - hints |= ExtendClientAreaChromeHints.PreferSystemChrome; + var hints = ExtendClientAreaChromeHints.NoChrome | ExtendClientAreaChromeHints.OSXThickTitleBar; + + if (SystemTitleBarEnabled) + { + hints |= ExtendClientAreaChromeHints.SystemChrome; + } + if (PreferSystemChromeEnabled) + { + hints |= ExtendClientAreaChromeHints.PreferSystemChrome; + } + ChromeHints = hints; } - - ChromeHints = hints; - }); + }; SystemTitleBarEnabled = true; TitleBarHeight = -1; } - + public ExtendClientAreaChromeHints ChromeHints { get { return _chromeHints; } diff --git a/samples/ControlCatalog/ViewModels/PlatformInformationViewModel.cs b/samples/ControlCatalog/ViewModels/PlatformInformationViewModel.cs index 42eac2f96a..21c87bab0f 100644 --- a/samples/ControlCatalog/ViewModels/PlatformInformationViewModel.cs +++ b/samples/ControlCatalog/ViewModels/PlatformInformationViewModel.cs @@ -9,6 +9,14 @@ public class PlatformInformationViewModel : ViewModelBase { public PlatformInformationViewModel() { + /* NOTE: + * ------------ + * The below API is not meant to be used in production Apps. + * If you need to consume this info, please use: + * - OperatingSystem ( https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem | if .NET 5 or greater) + * - or RuntimeInformation ( https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.runtimeinformation ) + */ + var runtimeInfo = AvaloniaLocator.Current.GetService()?.GetRuntimeInfo(); if (runtimeInfo is { } info) diff --git a/samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs b/samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs index 00d1da46e9..5bad6c4b0f 100644 --- a/samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs +++ b/samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs @@ -19,8 +19,6 @@ namespace ControlCatalog.ViewModels { public TransitioningContentControlPageViewModel() { - var assetLoader = AvaloniaLocator.Current.GetRequiredService(); - var images = new string[] { "delicate-arch-896885_640.jpg", @@ -31,7 +29,7 @@ namespace ControlCatalog.ViewModels foreach (var image in images) { var path = $"avares://ControlCatalog/Assets/{image}"; - Images.Add(new Bitmap(assetLoader.Open(new Uri(path)))); + Images.Add(new Bitmap(AssetLoader.Open(new Uri(path)))); } SetupTransitions(); @@ -250,7 +248,7 @@ namespace ControlCatalog.ViewModels }, Duration = Duration }; - tasks.Add(animation.RunAsync(from, null, cancellationToken)); + tasks.Add(animation.RunAsync(from, cancellationToken)); } if (to != null) @@ -280,7 +278,7 @@ namespace ControlCatalog.ViewModels }, Duration = Duration }; - tasks.Add(animation.RunAsync(to, null, cancellationToken)); + tasks.Add(animation.RunAsync(to, cancellationToken)); } await Task.WhenAll(tasks);