diff --git a/samples/ControlCatalog/MainView.xaml.cs b/samples/ControlCatalog/MainView.xaml.cs index 7133ddaa6a..7001eb41ea 100644 --- a/samples/ControlCatalog/MainView.xaml.cs +++ b/samples/ControlCatalog/MainView.xaml.cs @@ -2,10 +2,10 @@ using System; using System.Collections; using Avalonia; using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using Avalonia.Media; using Avalonia.Media.Immutable; -using Avalonia.Platform; using Avalonia.Themes.Fluent; using ControlCatalog.Models; using ControlCatalog.Pages; @@ -20,7 +20,7 @@ namespace ControlCatalog var sideBar = this.Get("Sidebar"); - if (AvaloniaLocator.Current?.GetService()?.GetRuntimeInfo().IsDesktop == true) + if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime) { var tabItems = (sideBar.Items as IList); tabItems?.Add(new TabItem() @@ -28,7 +28,6 @@ namespace ControlCatalog Header = "Screens", Content = new ScreenPage() }); - } var themes = this.Get("Themes"); diff --git a/samples/ControlCatalog/Pages/ScreenPage.cs b/samples/ControlCatalog/Pages/ScreenPage.cs index dde622d585..77da4fcb5f 100644 --- a/samples/ControlCatalog/Pages/ScreenPage.cs +++ b/samples/ControlCatalog/Pages/ScreenPage.cs @@ -2,7 +2,6 @@ using System; using System.Globalization; using Avalonia; using Avalonia.Controls; -using Avalonia.Markup.Xaml; using Avalonia.Media; using Avalonia.Platform; using Avalonia.Rendering; @@ -18,8 +17,10 @@ namespace ControlCatalog.Pages protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { base.OnAttachedToVisualTree(e); - Window w = (Window)VisualRoot!; - w.PositionChanged += (sender, args) => InvalidateVisual(); + if(VisualRoot is Window w) + { + w.PositionChanged += (_, _) => InvalidateVisual(); + } } public override void Render(DrawingContext context) @@ -27,7 +28,7 @@ namespace ControlCatalog.Pages base.Render(context); if (!(VisualRoot is Window w)) { - return; + return; } var screens = w.Screens.All; var scaling = ((IRenderRoot)w).RenderScaling;