From 5bf8b2dac9a7f05888a918aad9c059ac67287076 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:53:25 -0700 Subject: [PATCH 01/13] Add reused TrimmingEnable targets file, it contains a bunch of helper analyzers --- AvaloniaBehaviors.sln | 1 + build/TrimmingEnable.targets | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 build/TrimmingEnable.targets diff --git a/AvaloniaBehaviors.sln b/AvaloniaBehaviors.sln index cf4f72f9..77e1fd26 100644 --- a/AvaloniaBehaviors.sln +++ b/AvaloniaBehaviors.sln @@ -43,6 +43,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "props", "props", "{40A43022 build\SignAssembly.props = build\SignAssembly.props build\SourceLink.props = build\SourceLink.props build\XUnit.props = build\XUnit.props + build\TrimmingEnable.targets = build\TrimmingEnable.targets EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nuget", "nuget", "{721A55B7-C5B0-44E2-803A-56E291C672FE}" diff --git a/build/TrimmingEnable.targets b/build/TrimmingEnable.targets new file mode 100644 index 00000000..c74452a4 --- /dev/null +++ b/build/TrimmingEnable.targets @@ -0,0 +1,29 @@ + + + + false + true + false + true + + + + true + + + + true + + $(WarningsAsErrors);IL2000;IL2001;IL2002;IL2003;IL2004;IL2005;IL2006;IL2007;IL2008;IL2009;IL2010;IL2011;IL2012;IL2013;IL2014;IL2015;IL2016;IL2017;IL2018;IL2019;IL2020;IL2021;IL2022;IL2023;IL2024;IL2025;IL2026;IL2027;IL2028;IL2029;IL2030;IL2031;IL2032;IL2033;IL2034;IL2035;IL2036;IL2037;IL2038;IL2039;IL2040;IL2041;IL2042;IL2043;IL2044;IL2045;IL2046;IL2047;IL2048;IL2049;IL2050;IL2051;IL2052;IL2053;IL2054;IL2055;IL2056;IL2057;IL2058;IL2059;IL2060;IL2061;IL2062;IL2063;IL2064;IL2065;IL2066;IL2067;IL2068;IL2069;IL2070;IL2071;IL2072;IL2073;IL2074;IL2075;IL2076;IL2077;IL2078;IL2079;IL2080;IL2081;IL2082;IL2083;IL2084;IL2085;IL2086;IL2087;IL2088;IL2089;IL2090;IL2091;IL2092;IL2093;IL2094;IL2095;IL2096;IL2097;IL2098;IL2099;IL2100;IL2101;IL2102;IL2103;IL2104;IL2105;IL2106;IL2107;IL2108;IL2109;IL2110;IL2111;IL2112;IL2113;IL2114;IL2115;IL2116;IL2117;IL2118;IL2119;IL2120;IL2121;IL2122;IL2123;IL2124;IL2125;IL2126;IL2127;IL2128;IL2129;IL2130;IL2131;IL2132;IL2133;IL2134;IL2135;IL2136;IL2137;IL2138;IL2139;IL2140;IL2141;IL2142;IL2143;IL2144;IL2145;IL2146;IL2147;IL2148;IL2149;IL2150;IL2151;IL2152;IL2153;IL2154;IL2155;IL2156;IL2157 + + $(WarningsAsErrors);IL3050;IL3051;IL3052;IL3053;IL3054;IL3055;IL3056 + + + + $(WarningsAsErrors);CA1420;CA1421 + + + + + + From 368662b2a6afcee5644a71b7b6784aae6b03624e Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:53:49 -0700 Subject: [PATCH 02/13] Bump System.Reactive, as 6.0.1 version had AOT compatibility issue --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 13994342..baae8de2 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -14,7 +14,7 @@ - + From bb26b82e230fc7127105d2520e84d0c05785d208 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:54:49 -0700 Subject: [PATCH 03/13] Bump Avalonia version used in samples, enable compiled bindings --- Directory.Build.props | 1 + samples/BehaviorsTestApplication/Program.cs | 1 + .../Views/MainView.axaml | 5 ++-- .../Views/Pages/AdaptiveBehaviorView.axaml | 2 +- .../Pages/AddRemoveClassActionView.axaml | 2 +- .../Views/Pages/AdvancedView.axaml | 2 +- .../ButtonClickEventTriggerBehaviorView.axaml | 4 ++- .../Views/Pages/CallMethodActionView.axaml | 2 +- .../ChangeAvaloniaPropertyActionView.axaml | 2 +- .../Pages/ChangePropertyActionView.axaml | 2 +- .../Views/Pages/CustomActionView.axaml | 2 +- .../Views/Pages/CustomBehaviorView.axaml | 2 +- .../Views/Pages/DataTriggerBehaviorView.axaml | 2 +- .../Views/Pages/EditableTreeViewView.axaml | 2 +- .../Pages/EventTriggerBehaviorView.axaml | 2 +- .../Views/Pages/InvokeCommandActionView.axaml | 2 +- .../RoutedEventTriggerBehaviorView.axaml | 2 +- .../ValueChangedTriggerBehaviorView.axaml | 2 +- samples/DragAndDropSample/App.axaml | 5 ---- samples/DragAndDropSample/ViewLocator.cs | 29 ------------------- .../DragAndDropSample/Views/MainWindow.axaml | 3 +- samples/DraggableDemo/MainWindow.axaml | 2 +- 22 files changed, 24 insertions(+), 54 deletions(-) delete mode 100644 samples/DragAndDropSample/ViewLocator.cs diff --git a/Directory.Build.props b/Directory.Build.props index 75ff2ca6..370f948f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,6 +7,7 @@ Copyright © Wiesław Šoltés 2024 MIT https://github.com/wieslawsoltes/AvaloniaBehaviors + true latest diff --git a/samples/BehaviorsTestApplication/Program.cs b/samples/BehaviorsTestApplication/Program.cs index e961b9b9..41a27396 100644 --- a/samples/BehaviorsTestApplication/Program.cs +++ b/samples/BehaviorsTestApplication/Program.cs @@ -18,6 +18,7 @@ public static AppBuilder BuildAvaloniaApp() GC.KeepAlive(typeof(Interaction).Assembly); GC.KeepAlive(typeof(ComparisonConditionType).Assembly); return AppBuilder.Configure() + .WithInterFont() .UsePlatformDetect() .UseReactiveUI() .LogToTrace(); diff --git a/samples/BehaviorsTestApplication/Views/MainView.axaml b/samples/BehaviorsTestApplication/Views/MainView.axaml index 16a1993f..3856c46a 100644 --- a/samples/BehaviorsTestApplication/Views/MainView.axaml +++ b/samples/BehaviorsTestApplication/Views/MainView.axaml @@ -5,9 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:BehaviorsTestApplication.ViewModels" - x:CompileBindings="True" x:DataType="vm:MainWindowViewModel" - mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="700" - FontFamily="avares://Avalonia.Fonts.Inter/Assets#Inter"> + x:DataType="vm:MainWindowViewModel" + mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="700"> - diff --git a/samples/BehaviorsTestApplication/Views/Pages/EventTriggerBehaviorView.axaml b/samples/BehaviorsTestApplication/Views/Pages/EventTriggerBehaviorView.axaml index cb863f6e..6ae54483 100644 --- a/samples/BehaviorsTestApplication/Views/Pages/EventTriggerBehaviorView.axaml +++ b/samples/BehaviorsTestApplication/Views/Pages/EventTriggerBehaviorView.axaml @@ -4,7 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:BehaviorsTestApplication.ViewModels" - x:CompileBindings="True" x:DataType="vm:MainWindowViewModel" + x:DataType="vm:MainWindowViewModel" mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"> diff --git a/samples/BehaviorsTestApplication/Views/Pages/InvokeCommandActionView.axaml b/samples/BehaviorsTestApplication/Views/Pages/InvokeCommandActionView.axaml index 1f0c9598..9f2c6c78 100644 --- a/samples/BehaviorsTestApplication/Views/Pages/InvokeCommandActionView.axaml +++ b/samples/BehaviorsTestApplication/Views/Pages/InvokeCommandActionView.axaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:BehaviorsTestApplication.ViewModels" xmlns:reactive="using:System.Reactive" - x:CompileBindings="True" x:DataType="vm:MainWindowViewModel" + x:DataType="vm:MainWindowViewModel" mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"> diff --git a/samples/BehaviorsTestApplication/Views/Pages/RoutedEventTriggerBehaviorView.axaml b/samples/BehaviorsTestApplication/Views/Pages/RoutedEventTriggerBehaviorView.axaml index 6094d88f..26c76630 100644 --- a/samples/BehaviorsTestApplication/Views/Pages/RoutedEventTriggerBehaviorView.axaml +++ b/samples/BehaviorsTestApplication/Views/Pages/RoutedEventTriggerBehaviorView.axaml @@ -4,7 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:BehaviorsTestApplication.ViewModels" - x:CompileBindings="True" x:DataType="vm:MainWindowViewModel" + x:DataType="vm:MainWindowViewModel" mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"> diff --git a/samples/BehaviorsTestApplication/Views/Pages/ValueChangedTriggerBehaviorView.axaml b/samples/BehaviorsTestApplication/Views/Pages/ValueChangedTriggerBehaviorView.axaml index 156a0435..933481ac 100644 --- a/samples/BehaviorsTestApplication/Views/Pages/ValueChangedTriggerBehaviorView.axaml +++ b/samples/BehaviorsTestApplication/Views/Pages/ValueChangedTriggerBehaviorView.axaml @@ -4,7 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:BehaviorsTestApplication.ViewModels" - x:CompileBindings="True" x:DataType="vm:MainWindowViewModel" + x:DataType="vm:MainWindowViewModel" mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450"> diff --git a/samples/DragAndDropSample/App.axaml b/samples/DragAndDropSample/App.axaml index 197d3404..1295c48e 100644 --- a/samples/DragAndDropSample/App.axaml +++ b/samples/DragAndDropSample/App.axaml @@ -1,13 +1,8 @@ - - - - diff --git a/samples/DragAndDropSample/ViewLocator.cs b/samples/DragAndDropSample/ViewLocator.cs deleted file mode 100644 index e9f17949..00000000 --- a/samples/DragAndDropSample/ViewLocator.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using Avalonia.Controls; -using Avalonia.Controls.Templates; -using DragAndDropSample.ViewModels; - -namespace DragAndDropSample; - -public class ViewLocator : IDataTemplate -{ - public Control Build(object? data) - { - var name = data?.GetType().FullName?.Replace("ViewModel", "View"); - var type = name is null ? null : Type.GetType(name); - - if (type != null) - { - return (Control)Activator.CreateInstance(type)!; - } - else - { - return new TextBlock {Text = "Not Found: " + name}; - } - } - - public bool Match(object? data) - { - return data is ViewModelBase; - } -} diff --git a/samples/DragAndDropSample/Views/MainWindow.axaml b/samples/DragAndDropSample/Views/MainWindow.axaml index 18a014ce..74c0e786 100644 --- a/samples/DragAndDropSample/Views/MainWindow.axaml +++ b/samples/DragAndDropSample/Views/MainWindow.axaml @@ -8,7 +8,8 @@ x:Class="DragAndDropSample.Views.MainWindow" Icon="/Assets/avalonia-logo.ico" Width="650" WindowStartupLocation="CenterScreen" - Title="DragAndDropSample"> + Title="DragAndDropSample" + x:DataType="vm:MainWindowViewModel"> diff --git a/samples/DraggableDemo/MainWindow.axaml b/samples/DraggableDemo/MainWindow.axaml index caf3c531..f90cabec 100644 --- a/samples/DraggableDemo/MainWindow.axaml +++ b/samples/DraggableDemo/MainWindow.axaml @@ -6,7 +6,7 @@ xmlns:models="clr-namespace:DraggableDemo.Models" mc:Ignorable="d" d:DesignWidth="1200" d:DesignHeight="550" x:Class="DraggableDemo.MainWindow" - x:CompileBindings="True" x:DataType="local:MainWindow" + x:DataType="local:MainWindow" WindowState="Normal" WindowStartupLocation="CenterScreen" Width="1200" Height="550" Title="Draggable Controls Demo"> From 1fdd0c1f0134c3c3b3e859940db714b10012dd1c Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:55:08 -0700 Subject: [PATCH 04/13] Avoid Avalonia.Diagnostics in Release --- .../BehaviorsTestApplication/BehaviorsTestApplication.csproj | 2 +- samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs | 2 ++ samples/DragAndDropSample/DragAndDropSample.csproj | 2 +- samples/DraggableDemo/DraggableDemo.csproj | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/samples/BehaviorsTestApplication/BehaviorsTestApplication.csproj b/samples/BehaviorsTestApplication/BehaviorsTestApplication.csproj index 00f0a20e..f9706177 100644 --- a/samples/BehaviorsTestApplication/BehaviorsTestApplication.csproj +++ b/samples/BehaviorsTestApplication/BehaviorsTestApplication.csproj @@ -11,7 +11,7 @@ - + diff --git a/samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs b/samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs index e290eb6f..fb3ecef7 100644 --- a/samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs +++ b/samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs @@ -11,7 +11,9 @@ public MainWindow() { InitializeComponent(); DataContext = new MainWindowViewModel(); +#if DEBUG this.AttachDevTools(); +#endif } private void InitializeComponent() diff --git a/samples/DragAndDropSample/DragAndDropSample.csproj b/samples/DragAndDropSample/DragAndDropSample.csproj index ae9dd2e0..aaec6285 100644 --- a/samples/DragAndDropSample/DragAndDropSample.csproj +++ b/samples/DragAndDropSample/DragAndDropSample.csproj @@ -16,7 +16,7 @@ - + diff --git a/samples/DraggableDemo/DraggableDemo.csproj b/samples/DraggableDemo/DraggableDemo.csproj index 449be893..40e7a3a4 100644 --- a/samples/DraggableDemo/DraggableDemo.csproj +++ b/samples/DraggableDemo/DraggableDemo.csproj @@ -15,7 +15,7 @@ - + From db2d6c09b39fa759c2afbf89cbf75bf755de1676 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:56:00 -0700 Subject: [PATCH 05/13] Prepare Interactivity package for AOT compatibility, all behaviors and triggers *should not* raise errors all the time --- .../Avalonia.Xaml.Interactivity.csproj | 1 + src/Avalonia.Xaml.Interactivity/BehaviorOfT.cs | 2 -- src/Avalonia.Xaml.Interactivity/TriggerOfT.cs | 2 -- src/Avalonia.Xaml.Interactivity/TypeConverterHelper.cs | 5 +++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Xaml.Interactivity/Avalonia.Xaml.Interactivity.csproj b/src/Avalonia.Xaml.Interactivity/Avalonia.Xaml.Interactivity.csproj index 2d160795..a13ef81b 100644 --- a/src/Avalonia.Xaml.Interactivity/Avalonia.Xaml.Interactivity.csproj +++ b/src/Avalonia.Xaml.Interactivity/Avalonia.Xaml.Interactivity.csproj @@ -19,5 +19,6 @@ + diff --git a/src/Avalonia.Xaml.Interactivity/BehaviorOfT.cs b/src/Avalonia.Xaml.Interactivity/BehaviorOfT.cs index 26b8ff8a..b46ccef1 100644 --- a/src/Avalonia.Xaml.Interactivity/BehaviorOfT.cs +++ b/src/Avalonia.Xaml.Interactivity/BehaviorOfT.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics.CodeAnalysis; namespace Avalonia.Xaml.Interactivity; @@ -21,7 +20,6 @@ public abstract class Behavior : Behavior where T : AvaloniaObject /// /// Override this to hook up functionality to the /// - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] protected override void OnAttached() { base.OnAttached(); diff --git a/src/Avalonia.Xaml.Interactivity/TriggerOfT.cs b/src/Avalonia.Xaml.Interactivity/TriggerOfT.cs index 471c6968..b8d91f31 100644 --- a/src/Avalonia.Xaml.Interactivity/TriggerOfT.cs +++ b/src/Avalonia.Xaml.Interactivity/TriggerOfT.cs @@ -20,8 +20,6 @@ public abstract class Trigger : Trigger where T : AvaloniaObject /// /// Override this to hook up functionality to the /// - /// - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] protected override void OnAttached() { base.OnAttached(); diff --git a/src/Avalonia.Xaml.Interactivity/TypeConverterHelper.cs b/src/Avalonia.Xaml.Interactivity/TypeConverterHelper.cs index 1e366a8a..dec3e5f8 100644 --- a/src/Avalonia.Xaml.Interactivity/TypeConverterHelper.cs +++ b/src/Avalonia.Xaml.Interactivity/TypeConverterHelper.cs @@ -9,6 +9,7 @@ namespace Avalonia.Xaml.Interactivity; /// /// A helper class that enables converting values specified in markup (strings) to their object representation. /// +[RequiresUnreferencedCode("This functionality is not compatible with trimming.")] internal static class TypeConverterHelper { /// @@ -18,8 +19,8 @@ internal static class TypeConverterHelper /// The destination type. /// Object representation of the string value. /// destinationType cannot be null. - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] - public static object? Convert(string value, Type destinationType) + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "DynamicallyAccessedMembers handles most of the problems.")] + public static object? Convert(string value, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type destinationType) { if (destinationType is null) { From 2a398ec88323afcc6cd48c76d8531e49bc40d80a Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:56:25 -0700 Subject: [PATCH 06/13] Enable TrimmingEnable for Responsive, Events, Draggable and DragAndDrop packages --- .../Avalonia.Xaml.Interactions.DragAndDrop.csproj | 1 + .../TypedDragBehavior.cs | 3 +-- .../Avalonia.Xaml.Interactions.Draggable.csproj | 1 + .../Avalonia.Xaml.Interactions.Events.csproj | 1 + .../Avalonia.Xaml.Interactions.Responsive.csproj | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Xaml.Interactions.DragAndDrop/Avalonia.Xaml.Interactions.DragAndDrop.csproj b/src/Avalonia.Xaml.Interactions.DragAndDrop/Avalonia.Xaml.Interactions.DragAndDrop.csproj index 2de4d7cf..e5de0f88 100644 --- a/src/Avalonia.Xaml.Interactions.DragAndDrop/Avalonia.Xaml.Interactions.DragAndDrop.csproj +++ b/src/Avalonia.Xaml.Interactions.DragAndDrop/Avalonia.Xaml.Interactions.DragAndDrop.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Avalonia.Xaml.Interactions.DragAndDrop/TypedDragBehavior.cs b/src/Avalonia.Xaml.Interactions.DragAndDrop/TypedDragBehavior.cs index c03e5b9b..63f9967f 100644 --- a/src/Avalonia.Xaml.Interactions.DragAndDrop/TypedDragBehavior.cs +++ b/src/Avalonia.Xaml.Interactions.DragAndDrop/TypedDragBehavior.cs @@ -91,7 +91,6 @@ private async Task DoDragDrop(PointerEventArgs triggerEvent, object? value) await DragDrop.DoDragDrop(triggerEvent, data, effect); } - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] private void AssociatedObject_PointerPressed(object? sender, PointerPressedEventArgs e) { var properties = e.GetCurrentPoint(AssociatedObject).Properties; @@ -100,7 +99,7 @@ private void AssociatedObject_PointerPressed(object? sender, PointerPressedEvent if (e.Source is Control control && AssociatedObject?.DataContext == control.DataContext && DataType is not null - && DataType.IsAssignableFrom(control.DataContext?.GetType())) + && DataType.IsInstanceOfType(control.DataContext)) { _dragStartPoint = e.GetPosition(null); _triggerEvent = e; diff --git a/src/Avalonia.Xaml.Interactions.Draggable/Avalonia.Xaml.Interactions.Draggable.csproj b/src/Avalonia.Xaml.Interactions.Draggable/Avalonia.Xaml.Interactions.Draggable.csproj index 5f13b67d..0375fc99 100644 --- a/src/Avalonia.Xaml.Interactions.Draggable/Avalonia.Xaml.Interactions.Draggable.csproj +++ b/src/Avalonia.Xaml.Interactions.Draggable/Avalonia.Xaml.Interactions.Draggable.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Avalonia.Xaml.Interactions.Events/Avalonia.Xaml.Interactions.Events.csproj b/src/Avalonia.Xaml.Interactions.Events/Avalonia.Xaml.Interactions.Events.csproj index e9ffffce..297eca68 100644 --- a/src/Avalonia.Xaml.Interactions.Events/Avalonia.Xaml.Interactions.Events.csproj +++ b/src/Avalonia.Xaml.Interactions.Events/Avalonia.Xaml.Interactions.Events.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Avalonia.Xaml.Interactions.Responsive/Avalonia.Xaml.Interactions.Responsive.csproj b/src/Avalonia.Xaml.Interactions.Responsive/Avalonia.Xaml.Interactions.Responsive.csproj index de98e9a7..3229a4c8 100644 --- a/src/Avalonia.Xaml.Interactions.Responsive/Avalonia.Xaml.Interactions.Responsive.csproj +++ b/src/Avalonia.Xaml.Interactions.Responsive/Avalonia.Xaml.Interactions.Responsive.csproj @@ -19,6 +19,7 @@ + From f67219beb3428f47a2bdc10f3291f5d923282665 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:56:47 -0700 Subject: [PATCH 07/13] Avoid reflection based FromEventPattern from System.Reactive --- .../BindPointerOverBehavior.cs | 26 +++++++++---------- .../ExecuteCommandOnActivatedBehavior.cs | 17 ++++++------ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/Avalonia.Xaml.Interactions.Custom/BindPointerOverBehavior.cs b/src/Avalonia.Xaml.Interactions.Custom/BindPointerOverBehavior.cs index 6600335d..587969de 100644 --- a/src/Avalonia.Xaml.Interactions.Custom/BindPointerOverBehavior.cs +++ b/src/Avalonia.Xaml.Interactions.Custom/BindPointerOverBehavior.cs @@ -1,6 +1,4 @@ -using System.Reactive; using System.Reactive.Disposables; -using System.Reactive.Linq; using Avalonia.Controls; using Avalonia.Data; using Avalonia.Input; @@ -38,18 +36,20 @@ protected override void OnAttached(CompositeDisposable disposables) return; } - var dispose = Observable - .FromEventPattern(AssociatedObject, nameof(PropertyChanged)) - .Select(x => x.EventArgs) - .Subscribe(new AnonymousObserver(e => - { - if (e.Property == InputElement.IsPointerOverProperty) - { - IsPointerOver = e.NewValue is true; - } - })); - disposables.Add(dispose); + var control = AssociatedObject; + control.PropertyChanged += AssociatedObjectOnPropertyChanged; + disposables.Add(Disposable.Create(() => control.PropertyChanged -= AssociatedObjectOnPropertyChanged)); disposables.Add(Disposable.Create(() => IsPointerOver = false)); + + return; + + void AssociatedObjectOnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) + { + if (e.Property == InputElement.IsPointerOverProperty) + { + IsPointerOver = e.NewValue is true; + } + } } } diff --git a/src/Avalonia.Xaml.Interactions.Custom/ExecuteCommand/ExecuteCommandOnActivatedBehavior.cs b/src/Avalonia.Xaml.Interactions.Custom/ExecuteCommand/ExecuteCommandOnActivatedBehavior.cs index 43c709fa..699ac8f6 100644 --- a/src/Avalonia.Xaml.Interactions.Custom/ExecuteCommand/ExecuteCommandOnActivatedBehavior.cs +++ b/src/Avalonia.Xaml.Interactions.Custom/ExecuteCommand/ExecuteCommandOnActivatedBehavior.cs @@ -1,6 +1,5 @@ -using System.Reactive; +using System; using System.Reactive.Disposables; -using System.Reactive.Linq; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; @@ -23,14 +22,14 @@ protected override void OnAttachedToVisualTree(CompositeDisposable disposable) if (mainWindow is not null) { - var dispose = Observable - .FromEventPattern(mainWindow, nameof(mainWindow.Activated)) - .Subscribe(new AnonymousObserver>(e => - { - ExecuteCommand(); - })); - disposable.Add(dispose); + mainWindow.Activated += WindowOnActivated; + disposable.Add(Disposable.Create(() => mainWindow.Activated -= WindowOnActivated)); } } } + + private void WindowOnActivated(object? sender, EventArgs e) + { + ExecuteCommand(); + } } From e922f8e5cb49deea4fa7c7434d578fdab7a99e52 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:57:07 -0700 Subject: [PATCH 08/13] Mark ChangeAvaloniaPropertyAction as RequiresUnreferencedCode --- .../Actions/ChangeAvaloniaPropertyAction.cs | 2 +- .../Avalonia.Xaml.Interactions.Custom.csproj | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Xaml.Interactions.Custom/Actions/ChangeAvaloniaPropertyAction.cs b/src/Avalonia.Xaml.Interactions.Custom/Actions/ChangeAvaloniaPropertyAction.cs index f861b43b..7c82764f 100644 --- a/src/Avalonia.Xaml.Interactions.Custom/Actions/ChangeAvaloniaPropertyAction.cs +++ b/src/Avalonia.Xaml.Interactions.Custom/Actions/ChangeAvaloniaPropertyAction.cs @@ -10,6 +10,7 @@ namespace Avalonia.Xaml.Interactions.Custom; /// /// An action that will change a specified Avalonia property to a specified value when invoked. /// +[RequiresUnreferencedCode("This functionality is not compatible with trimming.")] public class ChangeAvaloniaPropertyAction : Avalonia.Xaml.Interactivity.Action { /// @@ -82,7 +83,6 @@ public override object Execute(object? sender, object? parameter) return false; } - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] private void UpdateAvaloniaPropertyValue(AvaloniaObject targetObject, AvaloniaProperty targetProperty) { ValidateTargetProperty(targetProperty); diff --git a/src/Avalonia.Xaml.Interactions.Custom/Avalonia.Xaml.Interactions.Custom.csproj b/src/Avalonia.Xaml.Interactions.Custom/Avalonia.Xaml.Interactions.Custom.csproj index 7bc10841..6a7e203e 100644 --- a/src/Avalonia.Xaml.Interactions.Custom/Avalonia.Xaml.Interactions.Custom.csproj +++ b/src/Avalonia.Xaml.Interactions.Custom/Avalonia.Xaml.Interactions.Custom.csproj @@ -20,6 +20,7 @@ + From 294d7094c9b79287fae2bbe7fc972b1ecf280110 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:57:43 -0700 Subject: [PATCH 09/13] Use TrimmingEnable on Interactions package, mark CallMethodAction, ChangePropertyAction, DataTriggerBehavior and EventTriggerBehavior RequiresUnreferencedCode --- .../Avalonia.Xaml.Interactions.csproj | 1 + src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs | 4 ++-- src/Avalonia.Xaml.Interactions/Core/ChangePropertyAction.cs | 1 + src/Avalonia.Xaml.Interactions/Core/DataTriggerBehavior.cs | 3 +-- src/Avalonia.Xaml.Interactions/Core/EventTriggerBehavior.cs | 1 + 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Xaml.Interactions/Avalonia.Xaml.Interactions.csproj b/src/Avalonia.Xaml.Interactions/Avalonia.Xaml.Interactions.csproj index b1fef9c4..8f96ba71 100644 --- a/src/Avalonia.Xaml.Interactions/Avalonia.Xaml.Interactions.csproj +++ b/src/Avalonia.Xaml.Interactions/Avalonia.Xaml.Interactions.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs b/src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs index 60cd984b..7595ec41 100644 --- a/src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs +++ b/src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs @@ -14,6 +14,7 @@ namespace Avalonia.Xaml.Interactions.Core; /// /// An action that calls a method on a specified object when invoked. /// +[RequiresUnreferencedCode("This functionality is not compatible with trimming.")] public class CallMethodAction : Avalonia.Xaml.Interactivity.Action { private Type? _targetObjectType; @@ -92,8 +93,7 @@ private static void TargetObjectChanged(AvaloniaPropertyChangedEventArgsThe that is passed to the action by the behavior. Generally this is or a target object. /// The value of this parameter is determined by the caller. /// True if the method is called; else false. - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] - public override object Execute(object? sender, object? parameter) + public virtual object Execute(object? sender, object? parameter) { if (!IsEnabled) { diff --git a/src/Avalonia.Xaml.Interactions/Core/ChangePropertyAction.cs b/src/Avalonia.Xaml.Interactions/Core/ChangePropertyAction.cs index ae89a323..9412dfe4 100644 --- a/src/Avalonia.Xaml.Interactions/Core/ChangePropertyAction.cs +++ b/src/Avalonia.Xaml.Interactions/Core/ChangePropertyAction.cs @@ -11,6 +11,7 @@ namespace Avalonia.Xaml.Interactions.Core; /// /// An action that will change a specified property to a specified value when invoked. /// +[RequiresUnreferencedCode("This functionality is not compatible with trimming.")] public class ChangePropertyAction : Avalonia.Xaml.Interactivity.Action { private static readonly char[] s_trimChars = ['(', ')']; diff --git a/src/Avalonia.Xaml.Interactions/Core/DataTriggerBehavior.cs b/src/Avalonia.Xaml.Interactions/Core/DataTriggerBehavior.cs index 9088f642..eee6855c 100644 --- a/src/Avalonia.Xaml.Interactions/Core/DataTriggerBehavior.cs +++ b/src/Avalonia.Xaml.Interactions/Core/DataTriggerBehavior.cs @@ -9,6 +9,7 @@ namespace Avalonia.Xaml.Interactions.Core; /// /// A behavior that performs actions when the bound data meets a specified condition. /// +[RequiresUnreferencedCode("This functionality is not compatible with trimming.")] public class DataTriggerBehavior : StyledElementTrigger { /// @@ -68,7 +69,6 @@ static DataTriggerBehavior() new AnonymousObserver>(OnValueChanged)); } - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] private static bool Compare(object? leftOperand, ComparisonConditionType operatorType, object? rightOperand) { if (leftOperand is not null && rightOperand is not null) @@ -124,7 +124,6 @@ private static bool Compare(object? leftOperand, ComparisonConditionType operato /// /// Evaluates both operands that implement the IComparable interface. /// - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] private static bool EvaluateComparable(IComparable leftOperand, ComparisonConditionType operatorType, IComparable rightOperand) { object? convertedOperand = null; diff --git a/src/Avalonia.Xaml.Interactions/Core/EventTriggerBehavior.cs b/src/Avalonia.Xaml.Interactions/Core/EventTriggerBehavior.cs index 9f8ca1d1..28fbf871 100644 --- a/src/Avalonia.Xaml.Interactions/Core/EventTriggerBehavior.cs +++ b/src/Avalonia.Xaml.Interactions/Core/EventTriggerBehavior.cs @@ -11,6 +11,7 @@ namespace Avalonia.Xaml.Interactions.Core; /// /// A behavior that listens for a specified event on its source and executes its actions when that event is fired. /// +[RequiresUnreferencedCode("This functionality is not compatible with trimming.")] public class EventTriggerBehavior : StyledElementTrigger { private const string EventNameDefaultValue = "AttachedToVisualTree"; From 66ff98add99abb6e8555bfc9e7025b50542e5854 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:57:56 -0700 Subject: [PATCH 10/13] Enable TrimmingEnable on main-package --- src/Avalonia.Xaml.Behaviors/Avalonia.Xaml.Behaviors.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Avalonia.Xaml.Behaviors/Avalonia.Xaml.Behaviors.csproj b/src/Avalonia.Xaml.Behaviors/Avalonia.Xaml.Behaviors.csproj index 1d620f86..708618ee 100644 --- a/src/Avalonia.Xaml.Behaviors/Avalonia.Xaml.Behaviors.csproj +++ b/src/Avalonia.Xaml.Behaviors/Avalonia.Xaml.Behaviors.csproj @@ -19,6 +19,7 @@ + From 861d3b5f945f982c36335889c9297ce9669fb5a7 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 18:58:15 -0700 Subject: [PATCH 11/13] Adjust samples to publish with AOT enabled --- .../BehaviorsTestApplication.csproj | 8 ++++++++ samples/DragAndDropSample/DragAndDropSample.csproj | 1 + samples/DraggableDemo/DraggableDemo.csproj | 1 + 3 files changed, 10 insertions(+) diff --git a/samples/BehaviorsTestApplication/BehaviorsTestApplication.csproj b/samples/BehaviorsTestApplication/BehaviorsTestApplication.csproj index f9706177..0b778bfa 100644 --- a/samples/BehaviorsTestApplication/BehaviorsTestApplication.csproj +++ b/samples/BehaviorsTestApplication/BehaviorsTestApplication.csproj @@ -6,6 +6,7 @@ False False enable + true @@ -17,6 +18,13 @@ + + + + + + + diff --git a/samples/DragAndDropSample/DragAndDropSample.csproj b/samples/DragAndDropSample/DragAndDropSample.csproj index aaec6285..097c89df 100644 --- a/samples/DragAndDropSample/DragAndDropSample.csproj +++ b/samples/DragAndDropSample/DragAndDropSample.csproj @@ -6,6 +6,7 @@ False False enable + true diff --git a/samples/DraggableDemo/DraggableDemo.csproj b/samples/DraggableDemo/DraggableDemo.csproj index 40e7a3a4..341ac4fb 100644 --- a/samples/DraggableDemo/DraggableDemo.csproj +++ b/samples/DraggableDemo/DraggableDemo.csproj @@ -6,6 +6,7 @@ False False enable + true From c314bec530555cb96bb50fe7f708d9e0b6c67504 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 19:10:23 -0700 Subject: [PATCH 12/13] Make sure tests work well with compiled bindings (as it's enabled globally now) --- .../Core/InvokeCommandAction001.axaml | 4 +++- .../Core/InvokeCommandAction002.axaml | 4 +++- .../Core/InvokeCommandAction003.axaml | 3 ++- .../Core/InvokeCommandAction004.axaml | 4 +++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction001.axaml b/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction001.axaml index 96d6491b..545eb090 100644 --- a/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction001.axaml +++ b/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction001.axaml @@ -1,7 +1,9 @@  + Title="InvokeCommandAction001" + x:DataType="core:InvokeCommandAction001"> diff --git a/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction002.axaml b/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction002.axaml index bcf7c2eb..b9fb6439 100644 --- a/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction002.axaml +++ b/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction002.axaml @@ -1,7 +1,9 @@  + Title="InvokeCommandAction002" + x:DataType="core:InvokeCommandAction002"> diff --git a/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction003.axaml b/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction003.axaml index 46afc540..c87a3bcf 100644 --- a/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction003.axaml +++ b/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction003.axaml @@ -2,7 +2,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="Avalonia.Xaml.Interactions.UnitTests.Core.InvokeCommandAction003" xmlns:local="clr-namespace:Avalonia.Xaml.Interactions.UnitTests.Core" - Title="InvokeCommandAction003"> + Title="InvokeCommandAction003" + x:DataType="local:InvokeCommandAction003"> diff --git a/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction004.axaml b/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction004.axaml index 8f9f662d..92f48bf0 100644 --- a/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction004.axaml +++ b/tests/Avalonia.Xaml.Interactions.UnitTests/Core/InvokeCommandAction004.axaml @@ -1,7 +1,9 @@  + Title="InvokeCommandAction004" + x:DataType="core:InvokeCommandAction004"> From 16c2d41302ea539dabe52340b73cbe537e11f8f5 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Thu, 24 Oct 2024 22:32:14 -0700 Subject: [PATCH 13/13] Adjustments after repo migration --- .../BehaviorsTestApplication/Views/MainWindow.axaml.cs | 8 -------- src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs | 2 +- .../StyledElementBehaviorOfT.cs | 1 - .../StyledElementTriggerOfT.cs | 1 - 4 files changed, 1 insertion(+), 11 deletions(-) diff --git a/samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs b/samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs index fb3ecef7..79b7efb4 100644 --- a/samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs +++ b/samples/BehaviorsTestApplication/Views/MainWindow.axaml.cs @@ -11,13 +11,5 @@ public MainWindow() { InitializeComponent(); DataContext = new MainWindowViewModel(); -#if DEBUG - this.AttachDevTools(); -#endif - } - - private void InitializeComponent() - { - AvaloniaXamlLoader.Load(this); } } diff --git a/src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs b/src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs index 7595ec41..5c8474b3 100644 --- a/src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs +++ b/src/Avalonia.Xaml.Interactions/Core/CallMethodAction.cs @@ -93,7 +93,7 @@ private static void TargetObjectChanged(AvaloniaPropertyChangedEventArgsThe that is passed to the action by the behavior. Generally this is or a target object. /// The value of this parameter is determined by the caller. /// True if the method is called; else false. - public virtual object Execute(object? sender, object? parameter) + public override object Execute(object? sender, object? parameter) { if (!IsEnabled) { diff --git a/src/Avalonia.Xaml.Interactivity/StyledElementBehaviorOfT.cs b/src/Avalonia.Xaml.Interactivity/StyledElementBehaviorOfT.cs index 77991526..bbd83009 100644 --- a/src/Avalonia.Xaml.Interactivity/StyledElementBehaviorOfT.cs +++ b/src/Avalonia.Xaml.Interactivity/StyledElementBehaviorOfT.cs @@ -21,7 +21,6 @@ public abstract class StyledElementBehavior : StyledElementBehavior where T : /// /// Override this to hook up functionality to the /// - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] protected override void OnAttached() { base.OnAttached(); diff --git a/src/Avalonia.Xaml.Interactivity/StyledElementTriggerOfT.cs b/src/Avalonia.Xaml.Interactivity/StyledElementTriggerOfT.cs index 55bc2c57..329d0d89 100644 --- a/src/Avalonia.Xaml.Interactivity/StyledElementTriggerOfT.cs +++ b/src/Avalonia.Xaml.Interactivity/StyledElementTriggerOfT.cs @@ -22,7 +22,6 @@ public abstract class StyledElementTrigger : StyledElementTrigger where T : A /// Override this to hook up functionality to the /// /// - [RequiresUnreferencedCode("This functionality is not compatible with trimming.")] protected override void OnAttached() { base.OnAttached();