From d500f9112101e440f334904a232e71a0f12bafc1 Mon Sep 17 00:00:00 2001 From: Tom Edwards <109803929+TomEdwardsEnscape@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:42:49 +0100 Subject: [PATCH] Enable use of new VS extension with ControlCatalog by compiling XAML files as AvaloniaXaml (#19971) Removed manual InitializeComponent definitions Replaced uses of Get, FindControl, etc. with generated fields --- samples/ControlCatalog/ControlCatalog.csproj | 4 +- .../ControlCatalog/DecoratedWindow.xaml.cs | 58 ++++----- samples/ControlCatalog/MainView.xaml | 27 +++-- samples/ControlCatalog/MainView.xaml.cs | 113 ++++++++---------- samples/ControlCatalog/MainWindow.xaml | 5 +- samples/ControlCatalog/MainWindow.xaml.cs | 13 +- .../Pages/AcceleratorPage.xaml.cs | 10 +- .../ControlCatalog/Pages/AcrylicPage.xaml.cs | 13 +- .../Pages/AdornerLayerPage.xaml.cs | 30 ++--- .../Pages/AutoCompleteBoxPage.xaml.cs | 35 ++---- .../ControlCatalog/Pages/BorderPage.xaml.cs | 10 +- .../Pages/ButtonSpinnerPage.xaml.cs | 12 +- samples/ControlCatalog/Pages/ButtonsPage.xaml | 2 +- .../ControlCatalog/Pages/ButtonsPage.xaml.cs | 16 +-- .../Pages/CalendarDatePickerPage.xaml.cs | 29 ++--- .../ControlCatalog/Pages/CalendarPage.xaml.cs | 24 ++-- .../ControlCatalog/Pages/CanvasPage.xaml.cs | 10 +- .../ControlCatalog/Pages/CarouselPage.xaml.cs | 40 ++----- .../ControlCatalog/Pages/CheckBoxPage.xaml.cs | 10 +- .../Pages/ClipboardPage.xaml.cs | 14 +-- .../Pages/ColorPickerPage.xaml.cs | 10 +- .../ControlCatalog/Pages/ComboBoxPage.xaml.cs | 14 +-- .../Pages/CompositionPage.axaml.cs | 8 +- .../Pages/ContainerQueryPage.xaml.cs | 10 +- .../Pages/ContextFlyoutPage.xaml | 15 +-- .../Pages/ContextFlyoutPage.xaml.cs | 48 ++------ .../ControlCatalog/Pages/ContextMenuPage.xaml | 4 +- .../Pages/ContextMenuPage.xaml.cs | 32 +---- .../ControlCatalog/Pages/CursorPage.xaml.cs | 10 +- .../Pages/CustomDrawing.xaml.cs | 43 ++----- .../ControlCatalog/Pages/DataGridPage.xaml.cs | 7 +- .../Pages/DateTimePickerPage.xaml.cs | 17 +-- .../ControlCatalog/Pages/DialogsPage.xaml.cs | 77 ++++++------ .../Pages/DragAndDropPage.xaml.cs | 19 +-- .../ControlCatalog/Pages/ExpanderPage.xaml.cs | 13 +- .../ControlCatalog/Pages/FlyoutsPage.axaml.cs | 14 +-- samples/ControlCatalog/Pages/GesturePage.cs | 53 +++----- .../ControlCatalog/Pages/ImagePage.xaml.cs | 33 ++--- .../Pages/LayoutTransformControlPage.xaml.cs | 10 +- .../ControlCatalog/Pages/ListBoxPage.xaml.cs | 8 +- samples/ControlCatalog/Pages/MenuPage.xaml.cs | 17 +-- .../Pages/NativeEmbedPage.xaml.cs | 23 ++-- .../Pages/NotificationsPage.xaml.cs | 12 +- .../Pages/NumericUpDownPage.xaml.cs | 9 +- .../Pages/OpenGl/OpenGlLeasePage.xaml | 6 +- .../Pages/OpenGl/OpenGlLeasePage.xaml.cs | 21 +--- .../ControlCatalog/Pages/OpenGlPage.xaml.cs | 17 ++- .../Pages/PlatformInfoPage.xaml.cs | 15 +-- .../ControlCatalog/Pages/PointersPage.xaml | 4 + .../ControlCatalog/Pages/PointersPage.xaml.cs | 27 +---- .../Pages/ProgressBarPage.xaml.cs | 10 +- .../Pages/RadioButtonPage.xaml.cs | 10 +- .../Pages/ScrollViewerPage.xaml.cs | 8 +- .../ControlCatalog/Pages/SliderPage.xaml.cs | 10 +- .../Pages/SplitViewPage.xaml.cs | 13 +- .../Pages/TabControlPage.xaml.cs | 12 +- .../ControlCatalog/Pages/TabStripPage.xaml.cs | 10 +- .../Pages/TextBlockPage.xaml.cs | 10 +- .../ControlCatalog/Pages/TextBoxPage.xaml.cs | 10 +- .../Pages/ToggleSwitchPage.xaml.cs | 13 +- .../ControlCatalog/Pages/ToolTipPage.xaml.cs | 12 +- .../TransitioningContentControlPage.axaml.cs | 7 -- .../ControlCatalog/Pages/TreeViewPage.xaml.cs | 8 +- .../ControlCatalog/Pages/ViewboxPage.xaml.cs | 8 +- .../Pages/WindowCustomizationsPage.xaml.cs | 13 +- .../Views/CustomNotificationView.xaml.cs | 10 +- 66 files changed, 362 insertions(+), 873 deletions(-) diff --git a/samples/ControlCatalog/ControlCatalog.csproj b/samples/ControlCatalog/ControlCatalog.csproj index cff0bb4e92..7bbff55907 100644 --- a/samples/ControlCatalog/ControlCatalog.csproj +++ b/samples/ControlCatalog/ControlCatalog.csproj @@ -9,9 +9,9 @@ %(Filename) - + Designer - + diff --git a/samples/ControlCatalog/DecoratedWindow.xaml.cs b/samples/ControlCatalog/DecoratedWindow.xaml.cs index eccfaca60f..bb87d982ba 100644 --- a/samples/ControlCatalog/DecoratedWindow.xaml.cs +++ b/samples/ControlCatalog/DecoratedWindow.xaml.cs @@ -1,53 +1,45 @@ -using Avalonia; using Avalonia.Controls; -using Avalonia.Markup.Xaml; -using System; using Avalonia.Input; namespace ControlCatalog { - public class DecoratedWindow : Window + public partial class DecoratedWindow : Window { public DecoratedWindow() { - this.InitializeComponent(); - } - - void SetupSide(string name, StandardCursorType cursor, WindowEdge edge) - { - var ctl = this.Get(name); - ctl.Cursor = new Cursor(cursor); - ctl.PointerPressed += (i, e) => - { - if (WindowState == WindowState.Normal) - BeginResizeDrag(edge, e); - }; - } - - private void InitializeComponent() - { - AvaloniaXamlLoader.Load(this); - this.Get("TitleBar").PointerPressed += (i, e) => + InitializeComponent(); + TitleBar.PointerPressed += (i, e) => { BeginMoveDrag(e); }; - SetupSide("Left", StandardCursorType.LeftSide, WindowEdge.West); - SetupSide("Right", StandardCursorType.RightSide, WindowEdge.East); - SetupSide("Top", StandardCursorType.TopSide, WindowEdge.North); - SetupSide("Bottom", StandardCursorType.BottomSide, WindowEdge.South); - SetupSide("TopLeft", StandardCursorType.TopLeftCorner, WindowEdge.NorthWest); - SetupSide("TopRight", StandardCursorType.TopRightCorner, WindowEdge.NorthEast); - SetupSide("BottomLeft", StandardCursorType.BottomLeftCorner, WindowEdge.SouthWest); - SetupSide("BottomRight", StandardCursorType.BottomRightCorner, WindowEdge.SouthEast); - this.Get - - - "; - var mfxt = this.Get("MenuFlyoutXamlText"); + var mfxt = this.MenuFlyoutXamlText; mfxt.Text = ""; - var afxt = this.Get("AttachedFlyoutXamlText"); + var afxt = this.AttachedFlyoutXamlText; afxt.Text = "\n" + " \n" + " \n" + @@ -63,7 +59,7 @@ namespace ControlCatalog.Pages "\n\n In DoubleTapped handler:\n" + "FlyoutBase.ShowAttachedFlyout(AttachedFlyoutPanel);"; - var sfxt = this.Get("SharedFlyoutXamlText"); + var sfxt = this.SharedFlyoutXamlText; sfxt.Text = "Declare a flyout in Resources:\n" + "\n" + " \n" + diff --git a/samples/ControlCatalog/Pages/GesturePage.cs b/samples/ControlCatalog/Pages/GesturePage.cs index 9164384eae..c480b512b4 100644 --- a/samples/ControlCatalog/Pages/GesturePage.cs +++ b/samples/ControlCatalog/Pages/GesturePage.cs @@ -1,75 +1,61 @@ using System; -using System.Numerics; using Avalonia; using Avalonia.Controls; using Avalonia.Input; using Avalonia.LogicalTree; -using Avalonia.Markup.Xaml; using Avalonia.Rendering.Composition; using Avalonia.Utilities; namespace ControlCatalog.Pages { - public class GesturePage : UserControl + public partial class GesturePage : UserControl { private bool _isInit; private double _currentScale; public GesturePage() { - this.InitializeComponent(); - } - - private void InitializeComponent() - { - AvaloniaXamlLoader.Load(this); + InitializeComponent(); } protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { base.OnAttachedToVisualTree(e); - if(_isInit) + if (_isInit) { return; } _isInit = true; - SetPullHandlers(this.Find("TopPullZone"), false); - SetPullHandlers(this.Find("BottomPullZone"), true); - SetPullHandlers(this.Find("RightPullZone"), true); - SetPullHandlers(this.Find("LeftPullZone"), false); + SetPullHandlers(TopPullZone, false); + SetPullHandlers(BottomPullZone, true); + SetPullHandlers(RightPullZone, true); + SetPullHandlers(LeftPullZone, false); - var image = this.Get("PinchImage"); + var image = PinchImage; SetPinchHandlers(image); - var reset = this.Get