From dbc3c802a32e632263270cacdcc5bcf572cd5f0a Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 17 Apr 2023 01:29:06 -0400 Subject: [PATCH 01/80] Add Analyzers project to the main package --- Avalonia.sln | 2 +- build/DevAnalyzers.props | 2 +- packages/Avalonia/Avalonia.csproj | 4 ++ .../Avalonia.Analyzers.csproj | 2 +- ...valoniaPropertyAnalyzer.CompileAnalyzer.cs | 0 .../AvaloniaPropertyAnalyzer.cs | 1 - .../Avalonia.Analyzers/GlobalSuppressions.cs | 8 +++ .../OnPropertyChangedOverrideAnalyzer.cs | 59 +++++++++++++++++++ 8 files changed, 74 insertions(+), 4 deletions(-) rename src/tools/{PublicAnalyzers => Avalonia.Analyzers}/Avalonia.Analyzers.csproj (97%) rename src/tools/{PublicAnalyzers => Avalonia.Analyzers}/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs (100%) rename src/tools/{PublicAnalyzers => Avalonia.Analyzers}/AvaloniaPropertyAnalyzer.cs (99%) create mode 100644 src/tools/Avalonia.Analyzers/GlobalSuppressions.cs create mode 100644 src/tools/Avalonia.Analyzers/OnPropertyChangedOverrideAnalyzer.cs diff --git a/Avalonia.sln b/Avalonia.sln index f33b782479..acbf1e6bbb 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -233,7 +233,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUIDemo", "samples\R EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GpuInterop", "samples\GpuInterop\GpuInterop.csproj", "{C810060E-3809-4B74-A125-F11533AF9C1B}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Analyzers", "src\tools\PublicAnalyzers\Avalonia.Analyzers.csproj", "{C692FE73-43DB-49CE-87FC-F03ED61F25C9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Analyzers", "src\tools\Avalonia.Analyzers\Avalonia.Analyzers.csproj", "{C692FE73-43DB-49CE-87FC-F03ED61F25C9}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{176582E8-46AF-416A-85C1-13A5C6744497}" ProjectSection(SolutionItems) = preProject diff --git a/build/DevAnalyzers.props b/build/DevAnalyzers.props index 7d021d051f..dffd3098c3 100644 --- a/build/DevAnalyzers.props +++ b/build/DevAnalyzers.props @@ -5,7 +5,7 @@ ReferenceOutputAssembly="false" OutputItemType="Analyzer" SetTargetFramework="TargetFramework=netstandard2.0"/> - + diff --git a/src/tools/PublicAnalyzers/Avalonia.Analyzers.csproj b/src/tools/Avalonia.Analyzers/Avalonia.Analyzers.csproj similarity index 97% rename from src/tools/PublicAnalyzers/Avalonia.Analyzers.csproj rename to src/tools/Avalonia.Analyzers/Avalonia.Analyzers.csproj index 31b8d08541..39eaab1289 100644 --- a/src/tools/PublicAnalyzers/Avalonia.Analyzers.csproj +++ b/src/tools/Avalonia.Analyzers/Avalonia.Analyzers.csproj @@ -11,7 +11,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs b/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs similarity index 100% rename from src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs rename to src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.CompileAnalyzer.cs diff --git a/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.cs b/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs similarity index 99% rename from src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.cs rename to src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs index d1d9071d17..d1ffd82f99 100644 --- a/src/tools/PublicAnalyzers/AvaloniaPropertyAnalyzer.cs +++ b/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs @@ -14,7 +14,6 @@ using Microsoft.CodeAnalysis.Operations; namespace Avalonia.Analyzers; [DiagnosticAnalyzer(LanguageNames.CSharp, LanguageNames.VisualBasic)] -[SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking")] public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer { private const string Category = "AvaloniaProperty"; diff --git a/src/tools/Avalonia.Analyzers/GlobalSuppressions.cs b/src/tools/Avalonia.Analyzers/GlobalSuppressions.cs new file mode 100644 index 0000000000..9428b904b8 --- /dev/null +++ b/src/tools/Avalonia.Analyzers/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("MicrosoftCodeAnalysisReleaseTracking", "RS2008:Enable analyzer release tracking")] diff --git a/src/tools/Avalonia.Analyzers/OnPropertyChangedOverrideAnalyzer.cs b/src/tools/Avalonia.Analyzers/OnPropertyChangedOverrideAnalyzer.cs new file mode 100644 index 0000000000..6fbfe28bd8 --- /dev/null +++ b/src/tools/Avalonia.Analyzers/OnPropertyChangedOverrideAnalyzer.cs @@ -0,0 +1,59 @@ +using System.Collections.Immutable; +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Diagnostics; + +namespace Avalonia.Analyzers; + +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public class OnPropertyChangedOverrideAnalyzer : DiagnosticAnalyzer +{ + public const string DiagnosticId = "AVA2001"; + + private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor( + DiagnosticId, + "Missing invoke base.OnPropertyChanged", + "Method '{0}' do not invoke base.{0}", + "Potential issue", + DiagnosticSeverity.Warning, + isEnabledByDefault: true, + description: "The OnPropertyChanged of the base class was not invoked in the override method declaration, which could lead to unwanted behavior."); + + public override ImmutableArray SupportedDiagnostics => ImmutableArray.Create(Rule); + + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); + context.EnableConcurrentExecution(); + context.RegisterSyntaxNodeAction(AnalyzeMethod, SyntaxKind.MethodDeclaration); + } + + private static void AnalyzeMethod(SyntaxNodeAnalysisContext context) + { + var method = (MethodDeclarationSyntax)context.Node; + if (context.SemanticModel.GetDeclaredSymbol(method, context.CancellationToken) is IMethodSymbol currentMethod + && currentMethod.Name == "OnPropertyChanged" + && currentMethod.OverriddenMethod is IMethodSymbol originalMethod) + { + var baseInvocations = method.Body?.DescendantNodes().OfType(); + if (baseInvocations?.Any() == true) + { + foreach (var baseInvocation in baseInvocations) + { + if (baseInvocation.Parent is SyntaxNode parent) + { + var targetSymbol = context.SemanticModel.GetSymbolInfo(parent, context.CancellationToken); + if (SymbolEqualityComparer.Default.Equals(targetSymbol.Symbol, originalMethod)) + { + return; + } + } + } + } + context.ReportDiagnostic(Diagnostic.Create(Rule, currentMethod.Locations[0], currentMethod.Name)); + } + } + +} From 4dbd7cb2a0e0878367ecf7dc5a38609f0b2066d4 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 17 Apr 2023 01:36:30 -0400 Subject: [PATCH 02/80] Disable most of analyzers --- .../AvaloniaPropertyAnalyzer.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs b/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs index d1ffd82f99..9eb4cecc8b 100644 --- a/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs +++ b/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs @@ -3,7 +3,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; using System.Collections.ObjectModel; -using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.Serialization; using Microsoft.CodeAnalysis; @@ -67,7 +66,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Type mismatch: AvaloniaProperty owner is {0}, which is not the containing type", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "The owner of an AvaloniaProperty should generally be the containing type. This ensures that the property can be used as expected in XAML.", TypeMismatchTag); @@ -77,7 +76,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Unexpected property use: {0} is neither owned by nor attached to {1}", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "It is possible to use any AvaloniaProperty with any AvaloniaObject. However, each AvaloniaProperty an object uses on itself should be either owned by that object, or attached to that object.", InappropriateReadWriteTag); @@ -87,7 +86,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Inappropriate assignment: An AvaloniaObject should use SetCurrentValue when setting its own StyledProperty or AttachedProperty values", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "The standard means of setting an AvaloniaProperty is to call the SetValue method (often via a CLR property setter). This will forcibly overwrite values from sources like styles and templates, " + "which is something that should only be done by consumers of the control, not the control itself. Controls which want to set their own values should instead call the SetCurrentValue method, or " + "refactor the property into a DirectProperty. An assignment is exempt from this diagnostic in two scenarios: when it is forwarding a constructor parameter, and when the target object is derived " + @@ -100,7 +99,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Superfluous owner: {0} is already an owner of {1} via {2}", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "Ownership of an AvaloniaProperty is inherited along the type hierarchy. There is no need for a derived type to assert ownership over a base type's properties. This diagnostic can be a symptom of an incorrect property owner elsewhere.", InappropriateReadWriteTag); @@ -110,7 +109,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Name collision: {0} has the same name as {1}", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "Querying for an AvaloniaProperty by name requires that each property associated with a type have a unique name.", NameCollisionTag); @@ -120,7 +119,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Name collision: {0} owns multiple Avalonia properties with the name '{1}' {2}", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "It is unclear which AvaloniaProperty this CLR property refers to. Ensure that each AvaloniaProperty associated with a type has a unique name. If you need to change behaviour of a base property in your class, call its OverrideMetadata or OverrideDefaultValue methods.", NameCollisionTag); @@ -170,7 +169,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Type mismatch: CLR property type differs from the value type of {0} {1}", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "The AvaloniaObject.GetValue and AvaloniaObject.SetValue methods are public, and do not call CLR properties on the owning type. A CLR property changing the value type (even when an implicit cast is possible) is ineffective and can lead to InvalidCastException to be thrown.", TypeMismatchTag, AssociatedClrPropertyTag); From ead92a6122a4617b19b40356fd537b50d91fa449 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 17 Apr 2023 01:37:47 -0400 Subject: [PATCH 03/80] Fix SetCurrentValue warnings --- src/Avalonia.Base/Media/DashStyle.cs | 2 +- src/Avalonia.Base/Media/GradientBrush.cs | 2 +- src/Avalonia.Base/Media/PolyLineSegment.cs | 2 +- src/Avalonia.Base/Media/TransformGroup.cs | 9 +++++---- src/Avalonia.Controls/Calendar/CalendarButton.cs | 2 +- src/Avalonia.Controls/Calendar/CalendarDayButton.cs | 2 +- src/Avalonia.Controls/ColumnDefinition.cs | 2 +- src/Avalonia.Controls/Documents/Span.cs | 4 ++-- src/Avalonia.Controls/GridSplitter.cs | 2 +- src/Avalonia.Controls/LayoutTransformControl.cs | 4 ++-- src/Avalonia.Controls/NativeMenuItemSeparator.cs | 2 +- src/Avalonia.Controls/Primitives/OverlayPopupHost.cs | 2 +- .../Primitives/SelectingItemsControl.cs | 8 ++++---- src/Avalonia.Controls/Primitives/UniformGrid.cs | 2 +- .../PullToRefresh/RefreshVisualizer.cs | 2 +- src/Avalonia.Controls/RowDefinition.cs | 4 ++-- src/Avalonia.Controls/TabControl.cs | 11 ++++++----- src/Avalonia.Controls/TabItem.cs | 8 ++++---- src/Avalonia.Controls/ToggleSwitch.cs | 2 +- .../Diagnostics/Controls/Application.cs | 4 ++-- 20 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/Avalonia.Base/Media/DashStyle.cs b/src/Avalonia.Base/Media/DashStyle.cs index 4749bfa401..338737d2ab 100644 --- a/src/Avalonia.Base/Media/DashStyle.cs +++ b/src/Avalonia.Base/Media/DashStyle.cs @@ -46,7 +46,7 @@ namespace Avalonia.Media /// The dash sequence offset. public DashStyle(IEnumerable? dashes, double offset) { - Dashes = (dashes as AvaloniaList) ?? new AvaloniaList(dashes ?? Array.Empty()); + SetCurrentValue(DashesProperty, (dashes as AvaloniaList) ?? new AvaloniaList(dashes ?? Array.Empty())); Offset = offset; } diff --git a/src/Avalonia.Base/Media/GradientBrush.cs b/src/Avalonia.Base/Media/GradientBrush.cs index e1654a01b2..0ec753201a 100644 --- a/src/Avalonia.Base/Media/GradientBrush.cs +++ b/src/Avalonia.Base/Media/GradientBrush.cs @@ -40,7 +40,7 @@ namespace Avalonia.Media /// public GradientBrush() { - this.GradientStops = new GradientStops(); + SetCurrentValue(GradientStopsProperty, new GradientStops()); } /// diff --git a/src/Avalonia.Base/Media/PolyLineSegment.cs b/src/Avalonia.Base/Media/PolyLineSegment.cs index 5c48c11e19..7de5e1afa5 100644 --- a/src/Avalonia.Base/Media/PolyLineSegment.cs +++ b/src/Avalonia.Base/Media/PolyLineSegment.cs @@ -30,7 +30,7 @@ namespace Avalonia.Media /// public PolyLineSegment() { - Points = new Points(); + SetCurrentValue(PointsProperty, new Points()); } /// diff --git a/src/Avalonia.Base/Media/TransformGroup.cs b/src/Avalonia.Base/Media/TransformGroup.cs index 0465efd5a5..c048234f8c 100644 --- a/src/Avalonia.Base/Media/TransformGroup.cs +++ b/src/Avalonia.Base/Media/TransformGroup.cs @@ -13,15 +13,16 @@ namespace Avalonia.Media public TransformGroup() { - Children = new Transforms(); - Children.ResetBehavior = ResetBehavior.Remove; - Children.CollectionChanged += delegate + var children = new Transforms(); + children.ResetBehavior = ResetBehavior.Remove; + children.CollectionChanged += delegate { - Children.ForEachItem( + children.ForEachItem( (tr) => tr.Changed += ChildTransform_Changed, (tr) => tr.Changed -= ChildTransform_Changed, () => { }); }; + SetCurrentValue(ChildrenProperty, children); } private void ChildTransform_Changed(object? sender, System.EventArgs e) diff --git a/src/Avalonia.Controls/Calendar/CalendarButton.cs b/src/Avalonia.Controls/Calendar/CalendarButton.cs index d8672cbf18..b35298b101 100644 --- a/src/Avalonia.Controls/Calendar/CalendarButton.cs +++ b/src/Avalonia.Controls/Calendar/CalendarButton.cs @@ -39,7 +39,7 @@ namespace Avalonia.Controls.Primitives public CalendarButton() : base() { - Content = DateTimeHelper.GetCurrentDateFormat().AbbreviatedMonthNames[0]; + SetCurrentValue(ContentProperty, DateTimeHelper.GetCurrentDateFormat().AbbreviatedMonthNames[0]); } /// diff --git a/src/Avalonia.Controls/Calendar/CalendarDayButton.cs b/src/Avalonia.Controls/Calendar/CalendarDayButton.cs index 3d0befdba7..ea3ca8e8fc 100644 --- a/src/Avalonia.Controls/Calendar/CalendarDayButton.cs +++ b/src/Avalonia.Controls/Calendar/CalendarDayButton.cs @@ -34,7 +34,7 @@ namespace Avalonia.Controls.Primitives : base() { //Focusable = false; - Content = DefaultContent.ToString(CultureInfo.CurrentCulture); + SetCurrentValue(ContentProperty, DefaultContent.ToString(CultureInfo.CurrentCulture)); } /// diff --git a/src/Avalonia.Controls/ColumnDefinition.cs b/src/Avalonia.Controls/ColumnDefinition.cs index 2eb3ae3010..b28faba863 100644 --- a/src/Avalonia.Controls/ColumnDefinition.cs +++ b/src/Avalonia.Controls/ColumnDefinition.cs @@ -46,8 +46,8 @@ namespace Avalonia.Controls /// The width of the column. /// The width unit of the column. public ColumnDefinition(double value, GridUnitType type) + : this(new GridLength(value, type)) { - Width = new GridLength(value, type); } /// diff --git a/src/Avalonia.Controls/Documents/Span.cs b/src/Avalonia.Controls/Documents/Span.cs index d3565cbdd5..a4f3264c4d 100644 --- a/src/Avalonia.Controls/Documents/Span.cs +++ b/src/Avalonia.Controls/Documents/Span.cs @@ -20,10 +20,10 @@ namespace Avalonia.Controls.Documents public Span() { - Inlines = new InlineCollection + SetCurrentValue(InlinesProperty, new InlineCollection { LogicalChildren = LogicalChildren - }; + }); } /// diff --git a/src/Avalonia.Controls/GridSplitter.cs b/src/Avalonia.Controls/GridSplitter.cs index 4684304725..50d1004f34 100644 --- a/src/Avalonia.Controls/GridSplitter.cs +++ b/src/Avalonia.Controls/GridSplitter.cs @@ -707,7 +707,7 @@ namespace Avalonia.Controls RenderTransform = _translation }; - Child = _decorator; + SetCurrentValue(ChildProperty, _decorator); } /// diff --git a/src/Avalonia.Controls/LayoutTransformControl.cs b/src/Avalonia.Controls/LayoutTransformControl.cs index f747e278f0..02d2eeef5b 100644 --- a/src/Avalonia.Controls/LayoutTransformControl.cs +++ b/src/Avalonia.Controls/LayoutTransformControl.cs @@ -63,7 +63,7 @@ namespace Avalonia.Controls { if (TransformRoot == null || LayoutTransform == null) { - LayoutTransform = RenderTransform; + SetCurrentValue(LayoutTransformProperty, RenderTransform); return base.ArrangeOverride(finalSize); } @@ -176,7 +176,7 @@ namespace Avalonia.Controls else { _renderTransformChangedEvent?.Dispose(); - LayoutTransform = null; + SetCurrentValue(LayoutTransformProperty, null); } } } diff --git a/src/Avalonia.Controls/NativeMenuItemSeparator.cs b/src/Avalonia.Controls/NativeMenuItemSeparator.cs index f55d714884..55b3fd08de 100644 --- a/src/Avalonia.Controls/NativeMenuItemSeparator.cs +++ b/src/Avalonia.Controls/NativeMenuItemSeparator.cs @@ -4,7 +4,7 @@ { public NativeMenuItemSeparator() { - Header = "-"; + SetCurrentValue(HeaderProperty, "-"); } } } diff --git a/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs b/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs index 7ed055f2e5..0acc488885 100644 --- a/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs +++ b/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs @@ -31,7 +31,7 @@ namespace Avalonia.Controls.Primitives /// public void SetChild(Control? control) { - Content = control; + SetCurrentValue(ContentProperty, control); } /// diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index 663a315732..ac3e87c03d 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -701,7 +701,7 @@ namespace Avalonia.Controls.Primitives if (value is null) { // Clearing SelectedValueBinding makes the SelectedValue the item itself - SelectedValue = SelectedItem; + SetCurrentValue(SelectedValueProperty, SelectedItem); return; } @@ -721,7 +721,7 @@ namespace Avalonia.Controls.Primitives } // Re-evaluate SelectedValue with the new binding - SelectedValue = _bindingHelper.Evaluate(selectedItem); + SetCurrentValue(SelectedValueProperty, _bindingHelper.Evaluate(selectedItem)); } finally { @@ -1092,7 +1092,7 @@ namespace Avalonia.Controls.Primitives try { _isSelectionChangeActive = true; - SelectedValue = item; + SetCurrentValue(SelectedValueProperty, item); } finally { @@ -1106,7 +1106,7 @@ namespace Avalonia.Controls.Primitives try { _isSelectionChangeActive = true; - SelectedValue = _bindingHelper.Evaluate(item); + SetCurrentValue(SelectedValueProperty, _bindingHelper.Evaluate(item)); } finally { diff --git a/src/Avalonia.Controls/Primitives/UniformGrid.cs b/src/Avalonia.Controls/Primitives/UniformGrid.cs index 09554412db..fea35d867a 100644 --- a/src/Avalonia.Controls/Primitives/UniformGrid.cs +++ b/src/Avalonia.Controls/Primitives/UniformGrid.cs @@ -123,7 +123,7 @@ namespace Avalonia.Controls.Primitives if (FirstColumn >= Columns) { - FirstColumn = 0; + SetCurrentValue(FirstColumnProperty, 0); } var itemCount = FirstColumn; diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs index 8dc19eb1d4..e110396d95 100644 --- a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs +++ b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs @@ -192,7 +192,7 @@ namespace Avalonia.Controls UpdateContent(); }; - Content = _content; + SetCurrentValue(ContentProperty, _content); } else { diff --git a/src/Avalonia.Controls/RowDefinition.cs b/src/Avalonia.Controls/RowDefinition.cs index fac795035b..8aaaff8cc9 100644 --- a/src/Avalonia.Controls/RowDefinition.cs +++ b/src/Avalonia.Controls/RowDefinition.cs @@ -46,8 +46,8 @@ namespace Avalonia.Controls /// The height of the row. /// The height unit of the column. public RowDefinition(double value, GridUnitType type) + : this(new GridLength(value, type)) { - Height = new GridLength(value, type); } /// @@ -56,7 +56,7 @@ namespace Avalonia.Controls /// The height of the column. public RowDefinition(GridLength height) { - Height = height; + SetCurrentValue(HeightProperty, height); } /// diff --git a/src/Avalonia.Controls/TabControl.cs b/src/Avalonia.Controls/TabControl.cs index 74cf54beb8..502e128641 100644 --- a/src/Avalonia.Controls/TabControl.cs +++ b/src/Avalonia.Controls/TabControl.cs @@ -162,8 +162,8 @@ namespace Avalonia.Controls if (index == SelectedIndex && element is ContentControl container) { - SelectedContentTemplate = container.ContentTemplate; - SelectedContent = container.Content; + SetCurrentValue(SelectedContentTemplateProperty, container.ContentTemplate); + SetCurrentValue(SelectedContentProperty, container.Content); } } @@ -187,14 +187,15 @@ namespace Avalonia.Controls { if (SelectedIndex == -1) { - SelectedContent = SelectedContentTemplate = null; + SetCurrentValue(SelectedContentProperty, null); + SetCurrentValue(SelectedContentTemplateProperty, null); } else { var container = SelectedItem as IContentControl ?? ContainerFromIndex(SelectedIndex) as IContentControl; - SelectedContentTemplate = container?.ContentTemplate; - SelectedContent = container?.Content; + SetCurrentValue(SelectedContentTemplateProperty, container?.ContentTemplate); + SetCurrentValue(SelectedContentProperty, container?.Content); } } diff --git a/src/Avalonia.Controls/TabItem.cs b/src/Avalonia.Controls/TabItem.cs index 46265fb5bc..8303153a4b 100644 --- a/src/Avalonia.Controls/TabItem.cs +++ b/src/Avalonia.Controls/TabItem.cs @@ -66,14 +66,14 @@ namespace Avalonia.Controls { if (Header != headered.Header) { - Header = headered.Header; + SetCurrentValue(HeaderProperty, headered.Header); } } else { if (!(obj.NewValue is Control)) { - Header = obj.NewValue; + SetCurrentValue(HeaderProperty, obj.NewValue); } } } @@ -81,9 +81,9 @@ namespace Avalonia.Controls { if (Header == obj.OldValue) { - Header = obj.NewValue; + SetCurrentValue(HeaderProperty, obj.NewValue); } - } + } } } } diff --git a/src/Avalonia.Controls/ToggleSwitch.cs b/src/Avalonia.Controls/ToggleSwitch.cs index a28e9791f6..108deba257 100644 --- a/src/Avalonia.Controls/ToggleSwitch.cs +++ b/src/Avalonia.Controls/ToggleSwitch.cs @@ -201,7 +201,7 @@ namespace Avalonia.Controls } else { - IsChecked = shouldBecomeChecked; + SetCurrentValue(IsCheckedProperty, shouldBecomeChecked); } } else diff --git a/src/Avalonia.Diagnostics/Diagnostics/Controls/Application.cs b/src/Avalonia.Diagnostics/Diagnostics/Controls/Application.cs index 5bc9909ef3..fb0504ba1e 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Controls/Application.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Controls/Application.cs @@ -37,7 +37,7 @@ namespace Avalonia.Diagnostics.Controls _ => null }; - RequestedThemeVariant = application.RequestedThemeVariant; + SetCurrentValue(RequestedThemeVariantProperty, application.RequestedThemeVariant); _application.PropertyChanged += ApplicationOnPropertyChanged; } @@ -131,7 +131,7 @@ namespace Avalonia.Diagnostics.Controls { if (e.Property == Avalonia.Application.RequestedThemeVariantProperty) { - RequestedThemeVariant = e.GetNewValue(); + SetCurrentValue(RequestedThemeVariantProperty, e.GetNewValue()); } } From e909bdb005121766a253194663c0f3e5bd636d0d Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 17 Apr 2023 01:38:32 -0400 Subject: [PATCH 04/80] Fix some other AVP warnings --- .../Pages/CustomDrawingExampleControl.cs | 11 +++++------ src/Avalonia.Controls/DefinitionBase.cs | 12 ++---------- src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs | 2 +- src/Avalonia.Controls/MenuItem.cs | 6 ------ .../PullToRefresh/RefreshVisualizer.cs | 2 +- src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj | 1 + .../Avalonia.Themes.Fluent.csproj | 1 + .../Avalonia.Themes.Simple.csproj | 1 + 8 files changed, 12 insertions(+), 24 deletions(-) diff --git a/samples/ControlCatalog/Pages/CustomDrawingExampleControl.cs b/samples/ControlCatalog/Pages/CustomDrawingExampleControl.cs index 549cf3d740..782435ae06 100644 --- a/samples/ControlCatalog/Pages/CustomDrawingExampleControl.cs +++ b/samples/ControlCatalog/Pages/CustomDrawingExampleControl.cs @@ -19,18 +19,16 @@ namespace ControlCatalog.Pages public static readonly StyledProperty ScaleProperty = AvaloniaProperty.Register(nameof(Scale), 1.0d); public double Scale { get => GetValue(ScaleProperty); set => SetValue(ScaleProperty, value); } - public static readonly StyledProperty RotationProperty = AvaloniaProperty.Register(nameof(Rotation)); + public static readonly StyledProperty RotationProperty = AvaloniaProperty.Register(nameof(Rotation), + coerce: (_, val) => val % (Math.PI * 2)); + /// /// Rotation, measured in Radians! /// public double Rotation { get => GetValue(RotationProperty); - set - { - double valueToUse = value % (Math.PI * 2); - SetValue(RotationProperty, valueToUse); - } + set => SetValue(RotationProperty, value); } public static readonly StyledProperty ViewportCenterYProperty = AvaloniaProperty.Register(nameof(ViewportCenterY), 0.0d); @@ -213,5 +211,6 @@ namespace ControlCatalog.Pages return workingPoint; } + } } diff --git a/src/Avalonia.Controls/DefinitionBase.cs b/src/Avalonia.Controls/DefinitionBase.cs index eb587fb157..d0752b8aa6 100644 --- a/src/Avalonia.Controls/DefinitionBase.cs +++ b/src/Avalonia.Controls/DefinitionBase.cs @@ -37,7 +37,7 @@ namespace Avalonia.Controls { // start with getting SharedSizeGroup value. // this property is NOT inherited which should result in better overall perf. - if (SharedSizeGroup is { } sharedSizeGroupId && PrivateSharedSizeScope is { } privateSharedSizeScope) + if (SharedSizeGroup is { } sharedSizeGroupId && GetValue(PrivateSharedSizeScopeProperty) is { } privateSharedSizeScope) { _sharedState = privateSharedSizeScope.EnsureSharedState(sharedSizeGroupId); _sharedState.AddMember(this); @@ -333,7 +333,7 @@ namespace Avalonia.Controls if (definition._sharedState == null && sharedSizeGroupId != null - && definition.PrivateSharedSizeScope is { } privateSharedSizeScope) + && definition.GetValue(PrivateSharedSizeScopeProperty) is { } privateSharedSizeScope) { // if definition is not registered and both: shared size group id AND private shared scope // are available, then register definition. @@ -412,14 +412,6 @@ namespace Avalonia.Controls } } - /// - /// Private getter of shared state collection dynamic property. - /// - private SharedSizeScope? PrivateSharedSizeScope - { - get { return GetValue(PrivateSharedSizeScopeProperty); } - } - /// /// Convenience accessor to UseSharedMinimum flag /// diff --git a/src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs b/src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs index 9ed4737c7c..5b23b5030f 100644 --- a/src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs +++ b/src/Avalonia.Controls/Flyouts/PopupFlyoutBase.cs @@ -44,7 +44,7 @@ namespace Avalonia.Controls.Primitives /// Defines the property /// public static readonly StyledProperty OverlayInputPassThroughElementProperty = - Popup.OverlayInputPassThroughElementProperty.AddOwner(); + Popup.OverlayInputPassThroughElementProperty.AddOwner(); private readonly Lazy _popupLazy; private Rect? _enlargedPopupRect; diff --git a/src/Avalonia.Controls/MenuItem.cs b/src/Avalonia.Controls/MenuItem.cs index a0dbf33a1d..72febcfedb 100644 --- a/src/Avalonia.Controls/MenuItem.cs +++ b/src/Avalonia.Controls/MenuItem.cs @@ -53,12 +53,6 @@ namespace Avalonia.Controls public static readonly StyledProperty InputGestureProperty = AvaloniaProperty.Register(nameof(InputGesture)); - /// - /// Defines the property. - /// - public static readonly StyledProperty IsSelectedProperty = - SelectingItemsControl.IsSelectedProperty.AddOwner(); - /// /// Defines the property. /// diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs index e110396d95..db83977bc6 100644 --- a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs +++ b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs @@ -99,7 +99,7 @@ namespace Avalonia.Controls } } - internal PullDirection PullDirection + public PullDirection PullDirection { get => GetValue(PullDirectionProperty); set => SetValue(PullDirectionProperty, value); diff --git a/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj b/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj index 22ee548823..4cae8e82df 100644 --- a/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj +++ b/src/Avalonia.ReactiveUI/Avalonia.ReactiveUI.csproj @@ -12,4 +12,5 @@ + diff --git a/src/Avalonia.Themes.Fluent/Avalonia.Themes.Fluent.csproj b/src/Avalonia.Themes.Fluent/Avalonia.Themes.Fluent.csproj index 8d266ce82f..e63a0c9c26 100644 --- a/src/Avalonia.Themes.Fluent/Avalonia.Themes.Fluent.csproj +++ b/src/Avalonia.Themes.Fluent/Avalonia.Themes.Fluent.csproj @@ -15,4 +15,5 @@ + diff --git a/src/Avalonia.Themes.Simple/Avalonia.Themes.Simple.csproj b/src/Avalonia.Themes.Simple/Avalonia.Themes.Simple.csproj index 4aa6b66743..03193599ed 100644 --- a/src/Avalonia.Themes.Simple/Avalonia.Themes.Simple.csproj +++ b/src/Avalonia.Themes.Simple/Avalonia.Themes.Simple.csproj @@ -15,4 +15,5 @@ + From a9688a83a1d7aa68068434a625078b114b5af998 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 17 Apr 2023 01:38:55 -0400 Subject: [PATCH 05/80] Suppress warnings that are expected behavior --- src/Avalonia.Base/ClassBindingManager.cs | 2 ++ src/Avalonia.Base/StyledElement.cs | 1 + src/Avalonia.Base/Styling/ThemeVariant.cs | 4 ++++ src/Avalonia.Base/Visual.cs | 1 + src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs | 2 ++ src/Avalonia.Controls/ContextMenu.cs | 2 ++ src/Avalonia.Controls/ListBox.cs | 8 ++++++++ src/Avalonia.Controls/Primitives/VisualLayerManager.cs | 3 +++ src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs | 1 + .../SplitView/SplitViewTemplateSettings.cs | 2 ++ src/Avalonia.Controls/TabControl.cs | 2 ++ src/Avalonia.Controls/TabItem.cs | 2 ++ src/Avalonia.Controls/TopLevel.cs | 4 ++-- src/Avalonia.ReactiveUI/ReactiveUserControl.cs | 1 + src/Avalonia.ReactiveUI/ReactiveWindow.cs | 1 + 15 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Base/ClassBindingManager.cs b/src/Avalonia.Base/ClassBindingManager.cs index a9726cb86e..55f3a7892a 100644 --- a/src/Avalonia.Base/ClassBindingManager.cs +++ b/src/Avalonia.Base/ClassBindingManager.cs @@ -17,6 +17,8 @@ namespace Avalonia return target.Bind(prop, source, anchor); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1001:The same AvaloniaProperty should not be registered twice", + Justification = "Classes.attr binding feature is implemented using intermediate avalonia properties for each class")] private static AvaloniaProperty RegisterClassProxyProperty(string className) { var prop = AvaloniaProperty.Register("__AvaloniaReserved::Classes::" + className); diff --git a/src/Avalonia.Base/StyledElement.cs b/src/Avalonia.Base/StyledElement.cs index 5881efce1e..3270fe4614 100644 --- a/src/Avalonia.Base/StyledElement.cs +++ b/src/Avalonia.Base/StyledElement.cs @@ -289,6 +289,7 @@ namespace Avalonia public StyledElement? Parent { get; private set; } /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1030:StyledProperty accessors should not have side effects", Justification = "False positive?")] public ThemeVariant ActualThemeVariant => GetValue(ThemeVariant.ActualThemeVariantProperty); /// diff --git a/src/Avalonia.Base/Styling/ThemeVariant.cs b/src/Avalonia.Base/Styling/ThemeVariant.cs index 389136b0f5..23bc15dfa7 100644 --- a/src/Avalonia.Base/Styling/ThemeVariant.cs +++ b/src/Avalonia.Base/Styling/ThemeVariant.cs @@ -9,6 +9,10 @@ namespace Avalonia.Styling; /// Specifies a UI theme variant that should be used for the Control and Application types. /// [TypeConverter(typeof(ThemeVariantTypeConverter))] +[System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1010:AvaloniaProperty objects should be owned by the type in which they are stored", + Justification = "ActualThemeVariant and RequestedThemeVariant properties are shared Avalonia.Base and Avalonia.Controls projects," + + "but shouldn't be visible on the StyledElement class." + + "Ideally we woould introduce readonly styled properties.")] public sealed record ThemeVariant { /// diff --git a/src/Avalonia.Base/Visual.cs b/src/Avalonia.Base/Visual.cs index 79cc760fc6..8717b5340a 100644 --- a/src/Avalonia.Base/Visual.cs +++ b/src/Avalonia.Base/Visual.cs @@ -329,6 +329,7 @@ namespace Avalonia /// /// Gets the control's parent visual. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1032", Justification = "GetVisualParent extension method is supposed to be used instead.")] internal Visual? VisualParent => _visualParent; /// diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs index e10cc1d100..20711eecbc 100644 --- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs @@ -2042,6 +2042,8 @@ namespace Avalonia.Controls /// /// Identifies the Value dependency property. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1002:AvaloniaProperty objects should not be owned by a generic type", + Justification = "This property is not supposed to be used from XAML.")] public static readonly StyledProperty ValueProperty = AvaloniaProperty.Register, T>(nameof(Value)); diff --git a/src/Avalonia.Controls/ContextMenu.cs b/src/Avalonia.Controls/ContextMenu.cs index fc4b11bd4a..63e28ea14d 100644 --- a/src/Avalonia.Controls/ContextMenu.cs +++ b/src/Avalonia.Controls/ContextMenu.cs @@ -56,6 +56,8 @@ namespace Avalonia.Controls /// /// Defines the property. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1013", + Justification = "We keep PlacementModeProperty for backward compatibility.")] public static readonly StyledProperty PlacementProperty = Popup.PlacementProperty.AddOwner(); diff --git a/src/Avalonia.Controls/ListBox.cs b/src/Avalonia.Controls/ListBox.cs index e665c2db90..e5f0b50555 100644 --- a/src/Avalonia.Controls/ListBox.cs +++ b/src/Avalonia.Controls/ListBox.cs @@ -29,18 +29,24 @@ namespace Avalonia.Controls /// /// Defines the property. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1010", + Justification = "This property is owned by SelectingItemsControl, but protected there. ListBox changes its visibility.")] public static readonly new DirectProperty SelectedItemsProperty = SelectingItemsControl.SelectedItemsProperty; /// /// Defines the property. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1010", + Justification = "This property is owned by SelectingItemsControl, but protected there. ListBox changes its visibility.")] public static readonly new DirectProperty SelectionProperty = SelectingItemsControl.SelectionProperty; /// /// Defines the property. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1010", + Justification = "This property is owned by SelectingItemsControl, but protected there. ListBox changes its visibility.")] public static readonly new StyledProperty SelectionModeProperty = SelectingItemsControl.SelectionModeProperty; @@ -84,6 +90,8 @@ namespace Avalonia.Controls /// Note that the selection mode only applies to selections made via user interaction. /// Multiple selections can be made programmatically regardless of the value of this property. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1012", + Justification = "This property is owned by SelectingItemsControl, but protected there. ListBox changes its visibility.")] public new SelectionMode SelectionMode { get { return base.SelectionMode; } diff --git a/src/Avalonia.Controls/Primitives/VisualLayerManager.cs b/src/Avalonia.Controls/Primitives/VisualLayerManager.cs index 351ed5d716..35676474dd 100644 --- a/src/Avalonia.Controls/Primitives/VisualLayerManager.cs +++ b/src/Avalonia.Controls/Primitives/VisualLayerManager.cs @@ -29,6 +29,9 @@ namespace Avalonia.Controls.Primitives } } + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1030")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1031", + Justification = "A hack to make ChromeOverlayLayer lazily creatable. It is expected that GetValue(ChromeOverlayLayerProperty) alone won't work.")] public ChromeOverlayLayer ChromeOverlayLayer { get diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs index db83977bc6..45227eef77 100644 --- a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs +++ b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs @@ -71,6 +71,7 @@ namespace Avalonia.Controls /// /// Gets or sets a value that indicates the refresh state of the visualizer. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1032", Justification = "False positive")] protected RefreshVisualizerState RefreshVisualizerState { get diff --git a/src/Avalonia.Controls/SplitView/SplitViewTemplateSettings.cs b/src/Avalonia.Controls/SplitView/SplitViewTemplateSettings.cs index f2cbf55986..8c59de7420 100644 --- a/src/Avalonia.Controls/SplitView/SplitViewTemplateSettings.cs +++ b/src/Avalonia.Controls/SplitView/SplitViewTemplateSettings.cs @@ -17,12 +17,14 @@ AvaloniaProperty.Register( nameof(PaneColumnGridLength)); + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1032", Justification = "This property is supposed to be a styled readonly property.")] public double ClosedPaneWidth { get => GetValue(ClosedPaneWidthProperty); internal set => SetValue(ClosedPaneWidthProperty, value); } + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1032", Justification = "This property is supposed to be a styled readonly property.")] public GridLength PaneColumnGridLength { get => GetValue(PaneColumnGridLengthProperty); diff --git a/src/Avalonia.Controls/TabControl.cs b/src/Avalonia.Controls/TabControl.cs index 502e128641..2e27cfd123 100644 --- a/src/Avalonia.Controls/TabControl.cs +++ b/src/Avalonia.Controls/TabControl.cs @@ -115,6 +115,7 @@ namespace Avalonia.Controls /// /// The content of the selected tab. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1032", Justification = "This property is supposed to be a styled readonly property.")] public object? SelectedContent { get { return GetValue(SelectedContentProperty); } @@ -127,6 +128,7 @@ namespace Avalonia.Controls /// /// The content template of the selected tab. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1032", Justification = "This property is supposed to be a styled readonly property.")] public IDataTemplate? SelectedContentTemplate { get { return GetValue(SelectedContentTemplateProperty); } diff --git a/src/Avalonia.Controls/TabItem.cs b/src/Avalonia.Controls/TabItem.cs index 8303153a4b..60e9a7c88c 100644 --- a/src/Avalonia.Controls/TabItem.cs +++ b/src/Avalonia.Controls/TabItem.cs @@ -42,6 +42,8 @@ namespace Avalonia.Controls /// /// The tab strip placement. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1031", + Justification = "This property is supposed to be inherited only and settable on parent TabControl.")] public Dock TabStripPlacement { get { return GetValue(TabStripPlacementProperty); } diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index 07b1e9b51f..f86554ec4f 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -83,11 +83,11 @@ namespace Avalonia.Controls /// public static readonly StyledProperty ActualThemeVariantProperty = - ThemeVariantScope.ActualThemeVariantProperty.AddOwner(); + ThemeVariantScope.ActualThemeVariantProperty.AddOwner(); /// public static readonly StyledProperty RequestedThemeVariantProperty = - ThemeVariantScope.RequestedThemeVariantProperty.AddOwner(); + ThemeVariantScope.RequestedThemeVariantProperty.AddOwner(); /// /// Defines the SystemBarColor attached property. diff --git a/src/Avalonia.ReactiveUI/ReactiveUserControl.cs b/src/Avalonia.ReactiveUI/ReactiveUserControl.cs index 21cdef2634..b0978dc3f6 100644 --- a/src/Avalonia.ReactiveUI/ReactiveUserControl.cs +++ b/src/Avalonia.ReactiveUI/ReactiveUserControl.cs @@ -17,6 +17,7 @@ namespace Avalonia.ReactiveUI /// ViewModel type. public class ReactiveUserControl : UserControl, IViewFor where TViewModel : class { + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1002", Justification = "Generic avalonia property is expected here.")] public static readonly StyledProperty ViewModelProperty = AvaloniaProperty .Register, TViewModel?>(nameof(ViewModel)); diff --git a/src/Avalonia.ReactiveUI/ReactiveWindow.cs b/src/Avalonia.ReactiveUI/ReactiveWindow.cs index 726fb3d661..14e9353096 100644 --- a/src/Avalonia.ReactiveUI/ReactiveWindow.cs +++ b/src/Avalonia.ReactiveUI/ReactiveWindow.cs @@ -17,6 +17,7 @@ namespace Avalonia.ReactiveUI /// ViewModel type. public class ReactiveWindow : Window, IViewFor where TViewModel : class { + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1002", Justification = "Generic avalonia property is expected here.")] public static readonly StyledProperty ViewModelProperty = AvaloniaProperty .Register, TViewModel?>(nameof(ViewModel)); From ad96c64aa26710a20eaafaeb06e62948b4b46ecf Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 17 Apr 2023 01:39:13 -0400 Subject: [PATCH 06/80] Mark Avalonia Analyzers as errors --- .editorconfig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.editorconfig b/.editorconfig index a144ec8843..6337257e8f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -186,6 +186,23 @@ csharp_wrap_before_ternary_opsigns = false # Avalonia DevAnalyzer preferences dotnet_diagnostic.AVADEV2001.severity = error +# Avalonia PublicAnalyzer preferences +dotnet_diagnostic.AVP1000.severity = error +dotnet_diagnostic.AVP1001.severity = error +dotnet_diagnostic.AVP1002.severity = error +dotnet_diagnostic.AVP1010.severity = error +dotnet_diagnostic.AVP1011.severity = error +dotnet_diagnostic.AVP1012.severity = error +dotnet_diagnostic.AVP1013.severity = error +dotnet_diagnostic.AVP1020.severity = error +dotnet_diagnostic.AVP1021.severity = error +dotnet_diagnostic.AVP1022.severity = error +dotnet_diagnostic.AVP1030.severity = error +dotnet_diagnostic.AVP1031.severity = error +dotnet_diagnostic.AVP1032.severity = error +dotnet_diagnostic.AVP1040.severity = error +dotnet_diagnostic.AVA2001.severity = error + # Xaml files [*.{xaml,axaml}] indent_size = 2 From 3c6fa1a578841b74d213b65ef1dac0191e19da26 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 17 Apr 2023 01:39:20 -0400 Subject: [PATCH 07/80] Fix missed ItemsSource --- src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml b/src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml index 6004d42120..5ec91ec9b9 100644 --- a/src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml @@ -3,7 +3,7 @@ - + Alabama Alaska Arizona @@ -12,7 +12,7 @@ Colorado Connecticut Delaware - + From d3fb8dee89dc9fd398ece99dd743b3b94bc4666f Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 17 Apr 2023 02:16:37 -0400 Subject: [PATCH 08/80] Build fixes --- samples/IntegrationTestApp/IntegrationTestApp.csproj | 1 + src/Avalonia.Controls/Application.cs | 2 ++ src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/samples/IntegrationTestApp/IntegrationTestApp.csproj b/samples/IntegrationTestApp/IntegrationTestApp.csproj index 1356eeb526..398743a353 100644 --- a/samples/IntegrationTestApp/IntegrationTestApp.csproj +++ b/samples/IntegrationTestApp/IntegrationTestApp.csproj @@ -3,6 +3,7 @@ WinExe net7.0 enable + $(NoWarn);AVP1012 diff --git a/src/Avalonia.Controls/Application.cs b/src/Avalonia.Controls/Application.cs index be3d5424fb..e907fd5988 100644 --- a/src/Avalonia.Controls/Application.cs +++ b/src/Avalonia.Controls/Application.cs @@ -94,6 +94,8 @@ namespace Avalonia } /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1031", Justification = "This property is supposed to be a styled readonly property.")] + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1030", Justification = "False positive.")] public ThemeVariant ActualThemeVariant => GetValue(ActualThemeVariantProperty); /// diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs index c17f5a19ab..fa956a79fe 100644 --- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteFilterMode.cs @@ -9,7 +9,7 @@ namespace Avalonia.Controls { /// /// Specifies how text in the text box portion of the - /// control is used to filter items specified by the + /// control is used to filter items specified by the /// property for display in the drop-down. /// public enum AutoCompleteFilterMode From 7e0a7d5aab0b9f83e5d423267031d1c0292b5040 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Tue, 18 Apr 2023 22:32:42 -0400 Subject: [PATCH 09/80] Disable more analyzers --- src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs b/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs index 9eb4cecc8b..7de0e8eac4 100644 --- a/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs +++ b/src/tools/Avalonia.Analyzers/AvaloniaPropertyAnalyzer.cs @@ -129,7 +129,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Bad name: An AvaloniaProperty named '{0}' is being assigned to {1}. These names do not relate.", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "An AvaloniaProperty should be stored in a field or property which contains its name. For example, a property named \"Brush\" should be assigned to a field called \"BrushProperty\".\nPrivate symbols are exempt from this diagnostic.", NameCollisionTag); @@ -139,7 +139,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Side effects: '{0}' is an AvaloniaProperty which can be {1} without the use of this CLR property. This {2} accessor should do nothing except call {3}.", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "The AvaloniaObject.GetValue and AvaloniaObject.SetValue methods are public, and do not call any user CLR properties. To execute code before or after the property is set, consider: 1) adding a Coercion method, b) adding a static observer with AvaloniaProperty.Changed.AddClassHandler, and/or c) overriding the AvaloniaObject.OnPropertyChanged method.", AssociatedClrPropertyTag); @@ -149,7 +149,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Missing accessor: {0} is {1}, but this CLR property lacks a {2} accessor", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "The AvaloniaObject.GetValue and AvaloniaObject.SetValue methods are public, and do not call CLR properties on the owning type. Not providing both CLR property accessors is ineffective.", AssociatedClrPropertyTag); @@ -159,7 +159,7 @@ public partial class AvaloniaPropertyAnalyzer : DiagnosticAnalyzer "Inconsistent accessibility: CLR {0} accessibility does not match accessibility of {1}", Category, DiagnosticSeverity.Warning, - isEnabledByDefault: true, + isEnabledByDefault: false, // TODO: autogenerate property metadata preserved in ref assembly "The AvaloniaObject.GetValue and AvaloniaObject.SetValue methods are public, and do not call CLR properties on the owning type. Defining a CLR property with different accessibility from its associated AvaloniaProperty is ineffective.", AssociatedClrPropertyTag); From f522845a583cf1f911c909625a64119c7e70b972 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Tue, 18 Apr 2023 22:37:34 -0400 Subject: [PATCH 10/80] Fix AutoCompleteBox --- .../Controls/AutoCompleteBox.xaml | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml b/src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml index 5ec91ec9b9..2113ae4cb0 100644 --- a/src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/AutoCompleteBox.xaml @@ -1,17 +1,20 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:generic="using:System.Collections.Generic"> - Alabama - Alaska - Arizona - Arkansas - California - Colorado - Connecticut - Delaware + + Alabama + Alaska + Arizona + Arkansas + California + Colorado + Connecticut + Delaware + From 6523320a7b73f13aba091069b2b58fd69692d25c Mon Sep 17 00:00:00 2001 From: Max Katz Date: Tue, 18 Apr 2023 22:43:38 -0400 Subject: [PATCH 11/80] Revert some of SetCurrentValue This reverts commit ead92a6122a4617b19b40356fd537b50d91fa449. --- src/Avalonia.Base/Media/DashStyle.cs | 2 +- src/Avalonia.Base/Media/GradientBrush.cs | 2 +- src/Avalonia.Base/Media/PolyLineSegment.cs | 2 +- src/Avalonia.Base/Media/TransformGroup.cs | 9 ++++----- src/Avalonia.Controls/Calendar/CalendarButton.cs | 2 +- src/Avalonia.Controls/Calendar/CalendarDayButton.cs | 2 +- src/Avalonia.Controls/Documents/Span.cs | 4 ++-- src/Avalonia.Controls/GridSplitter.cs | 2 +- src/Avalonia.Controls/LayoutTransformControl.cs | 2 +- src/Avalonia.Controls/NativeMenuItemSeparator.cs | 2 +- src/Avalonia.Controls/Primitives/OverlayPopupHost.cs | 2 +- .../Primitives/SelectingItemsControl.cs | 8 ++++---- .../PullToRefresh/RefreshVisualizer.cs | 2 +- src/Avalonia.Controls/TabControl.cs | 11 +++++------ src/Avalonia.Controls/TabItem.cs | 6 +++--- 15 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/Avalonia.Base/Media/DashStyle.cs b/src/Avalonia.Base/Media/DashStyle.cs index 338737d2ab..4749bfa401 100644 --- a/src/Avalonia.Base/Media/DashStyle.cs +++ b/src/Avalonia.Base/Media/DashStyle.cs @@ -46,7 +46,7 @@ namespace Avalonia.Media /// The dash sequence offset. public DashStyle(IEnumerable? dashes, double offset) { - SetCurrentValue(DashesProperty, (dashes as AvaloniaList) ?? new AvaloniaList(dashes ?? Array.Empty())); + Dashes = (dashes as AvaloniaList) ?? new AvaloniaList(dashes ?? Array.Empty()); Offset = offset; } diff --git a/src/Avalonia.Base/Media/GradientBrush.cs b/src/Avalonia.Base/Media/GradientBrush.cs index 0ec753201a..e1654a01b2 100644 --- a/src/Avalonia.Base/Media/GradientBrush.cs +++ b/src/Avalonia.Base/Media/GradientBrush.cs @@ -40,7 +40,7 @@ namespace Avalonia.Media /// public GradientBrush() { - SetCurrentValue(GradientStopsProperty, new GradientStops()); + this.GradientStops = new GradientStops(); } /// diff --git a/src/Avalonia.Base/Media/PolyLineSegment.cs b/src/Avalonia.Base/Media/PolyLineSegment.cs index 7de5e1afa5..5c48c11e19 100644 --- a/src/Avalonia.Base/Media/PolyLineSegment.cs +++ b/src/Avalonia.Base/Media/PolyLineSegment.cs @@ -30,7 +30,7 @@ namespace Avalonia.Media /// public PolyLineSegment() { - SetCurrentValue(PointsProperty, new Points()); + Points = new Points(); } /// diff --git a/src/Avalonia.Base/Media/TransformGroup.cs b/src/Avalonia.Base/Media/TransformGroup.cs index c048234f8c..0465efd5a5 100644 --- a/src/Avalonia.Base/Media/TransformGroup.cs +++ b/src/Avalonia.Base/Media/TransformGroup.cs @@ -13,16 +13,15 @@ namespace Avalonia.Media public TransformGroup() { - var children = new Transforms(); - children.ResetBehavior = ResetBehavior.Remove; - children.CollectionChanged += delegate + Children = new Transforms(); + Children.ResetBehavior = ResetBehavior.Remove; + Children.CollectionChanged += delegate { - children.ForEachItem( + Children.ForEachItem( (tr) => tr.Changed += ChildTransform_Changed, (tr) => tr.Changed -= ChildTransform_Changed, () => { }); }; - SetCurrentValue(ChildrenProperty, children); } private void ChildTransform_Changed(object? sender, System.EventArgs e) diff --git a/src/Avalonia.Controls/Calendar/CalendarButton.cs b/src/Avalonia.Controls/Calendar/CalendarButton.cs index b35298b101..d8672cbf18 100644 --- a/src/Avalonia.Controls/Calendar/CalendarButton.cs +++ b/src/Avalonia.Controls/Calendar/CalendarButton.cs @@ -39,7 +39,7 @@ namespace Avalonia.Controls.Primitives public CalendarButton() : base() { - SetCurrentValue(ContentProperty, DateTimeHelper.GetCurrentDateFormat().AbbreviatedMonthNames[0]); + Content = DateTimeHelper.GetCurrentDateFormat().AbbreviatedMonthNames[0]; } /// diff --git a/src/Avalonia.Controls/Calendar/CalendarDayButton.cs b/src/Avalonia.Controls/Calendar/CalendarDayButton.cs index ea3ca8e8fc..3d0befdba7 100644 --- a/src/Avalonia.Controls/Calendar/CalendarDayButton.cs +++ b/src/Avalonia.Controls/Calendar/CalendarDayButton.cs @@ -34,7 +34,7 @@ namespace Avalonia.Controls.Primitives : base() { //Focusable = false; - SetCurrentValue(ContentProperty, DefaultContent.ToString(CultureInfo.CurrentCulture)); + Content = DefaultContent.ToString(CultureInfo.CurrentCulture); } /// diff --git a/src/Avalonia.Controls/Documents/Span.cs b/src/Avalonia.Controls/Documents/Span.cs index a4f3264c4d..d3565cbdd5 100644 --- a/src/Avalonia.Controls/Documents/Span.cs +++ b/src/Avalonia.Controls/Documents/Span.cs @@ -20,10 +20,10 @@ namespace Avalonia.Controls.Documents public Span() { - SetCurrentValue(InlinesProperty, new InlineCollection + Inlines = new InlineCollection { LogicalChildren = LogicalChildren - }); + }; } /// diff --git a/src/Avalonia.Controls/GridSplitter.cs b/src/Avalonia.Controls/GridSplitter.cs index 50d1004f34..4684304725 100644 --- a/src/Avalonia.Controls/GridSplitter.cs +++ b/src/Avalonia.Controls/GridSplitter.cs @@ -707,7 +707,7 @@ namespace Avalonia.Controls RenderTransform = _translation }; - SetCurrentValue(ChildProperty, _decorator); + Child = _decorator; } /// diff --git a/src/Avalonia.Controls/LayoutTransformControl.cs b/src/Avalonia.Controls/LayoutTransformControl.cs index 02d2eeef5b..06069a897e 100644 --- a/src/Avalonia.Controls/LayoutTransformControl.cs +++ b/src/Avalonia.Controls/LayoutTransformControl.cs @@ -176,7 +176,7 @@ namespace Avalonia.Controls else { _renderTransformChangedEvent?.Dispose(); - SetCurrentValue(LayoutTransformProperty, null); + ClearValue(LayoutTransformProperty); } } } diff --git a/src/Avalonia.Controls/NativeMenuItemSeparator.cs b/src/Avalonia.Controls/NativeMenuItemSeparator.cs index 55b3fd08de..f55d714884 100644 --- a/src/Avalonia.Controls/NativeMenuItemSeparator.cs +++ b/src/Avalonia.Controls/NativeMenuItemSeparator.cs @@ -4,7 +4,7 @@ { public NativeMenuItemSeparator() { - SetCurrentValue(HeaderProperty, "-"); + Header = "-"; } } } diff --git a/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs b/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs index 0acc488885..7ed055f2e5 100644 --- a/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs +++ b/src/Avalonia.Controls/Primitives/OverlayPopupHost.cs @@ -31,7 +31,7 @@ namespace Avalonia.Controls.Primitives /// public void SetChild(Control? control) { - SetCurrentValue(ContentProperty, control); + Content = control; } /// diff --git a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs index ac3e87c03d..663a315732 100644 --- a/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs +++ b/src/Avalonia.Controls/Primitives/SelectingItemsControl.cs @@ -701,7 +701,7 @@ namespace Avalonia.Controls.Primitives if (value is null) { // Clearing SelectedValueBinding makes the SelectedValue the item itself - SetCurrentValue(SelectedValueProperty, SelectedItem); + SelectedValue = SelectedItem; return; } @@ -721,7 +721,7 @@ namespace Avalonia.Controls.Primitives } // Re-evaluate SelectedValue with the new binding - SetCurrentValue(SelectedValueProperty, _bindingHelper.Evaluate(selectedItem)); + SelectedValue = _bindingHelper.Evaluate(selectedItem); } finally { @@ -1092,7 +1092,7 @@ namespace Avalonia.Controls.Primitives try { _isSelectionChangeActive = true; - SetCurrentValue(SelectedValueProperty, item); + SelectedValue = item; } finally { @@ -1106,7 +1106,7 @@ namespace Avalonia.Controls.Primitives try { _isSelectionChangeActive = true; - SetCurrentValue(SelectedValueProperty, _bindingHelper.Evaluate(item)); + SelectedValue = _bindingHelper.Evaluate(item); } finally { diff --git a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs index 45227eef77..0ee2d69a73 100644 --- a/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs +++ b/src/Avalonia.Controls/PullToRefresh/RefreshVisualizer.cs @@ -193,7 +193,7 @@ namespace Avalonia.Controls UpdateContent(); }; - SetCurrentValue(ContentProperty, _content); + Content = _content; } else { diff --git a/src/Avalonia.Controls/TabControl.cs b/src/Avalonia.Controls/TabControl.cs index 2e27cfd123..310dd34382 100644 --- a/src/Avalonia.Controls/TabControl.cs +++ b/src/Avalonia.Controls/TabControl.cs @@ -164,8 +164,8 @@ namespace Avalonia.Controls if (index == SelectedIndex && element is ContentControl container) { - SetCurrentValue(SelectedContentTemplateProperty, container.ContentTemplate); - SetCurrentValue(SelectedContentProperty, container.Content); + SelectedContentTemplate = container.ContentTemplate; + SelectedContent = container.Content; } } @@ -189,15 +189,14 @@ namespace Avalonia.Controls { if (SelectedIndex == -1) { - SetCurrentValue(SelectedContentProperty, null); - SetCurrentValue(SelectedContentTemplateProperty, null); + SelectedContent = SelectedContentTemplate = null; } else { var container = SelectedItem as IContentControl ?? ContainerFromIndex(SelectedIndex) as IContentControl; - SetCurrentValue(SelectedContentTemplateProperty, container?.ContentTemplate); - SetCurrentValue(SelectedContentProperty, container?.Content); + SelectedContentTemplate = container?.ContentTemplate; + SelectedContent = container?.Content; } } diff --git a/src/Avalonia.Controls/TabItem.cs b/src/Avalonia.Controls/TabItem.cs index 60e9a7c88c..4068404952 100644 --- a/src/Avalonia.Controls/TabItem.cs +++ b/src/Avalonia.Controls/TabItem.cs @@ -68,14 +68,14 @@ namespace Avalonia.Controls { if (Header != headered.Header) { - SetCurrentValue(HeaderProperty, headered.Header); + Header = headered.Header; } } else { if (!(obj.NewValue is Control)) { - SetCurrentValue(HeaderProperty, obj.NewValue); + Header = obj.NewValue; } } } @@ -83,7 +83,7 @@ namespace Avalonia.Controls { if (Header == obj.OldValue) { - SetCurrentValue(HeaderProperty, obj.NewValue); + Header = obj.NewValue; } } } From 7d26c16a10ca97a69995af32cb913a6b11fcda6a Mon Sep 17 00:00:00 2001 From: Max Katz Date: Tue, 18 Apr 2023 22:47:53 -0400 Subject: [PATCH 12/80] Configure AVP1012 as a warning --- .editorconfig | 2 +- src/Avalonia.Base/Media/DashStyle.cs | 2 ++ src/Avalonia.Base/Media/GradientBrush.cs | 2 ++ src/Avalonia.Base/Media/PolyLineSegment.cs | 2 ++ src/Avalonia.Base/Media/TransformGroup.cs | 2 ++ src/Avalonia.Controls/Documents/Span.cs | 2 ++ 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 6337257e8f..d07618df6c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -192,7 +192,7 @@ dotnet_diagnostic.AVP1001.severity = error dotnet_diagnostic.AVP1002.severity = error dotnet_diagnostic.AVP1010.severity = error dotnet_diagnostic.AVP1011.severity = error -dotnet_diagnostic.AVP1012.severity = error +dotnet_diagnostic.AVP1012.severity = warning dotnet_diagnostic.AVP1013.severity = error dotnet_diagnostic.AVP1020.severity = error dotnet_diagnostic.AVP1021.severity = error diff --git a/src/Avalonia.Base/Media/DashStyle.cs b/src/Avalonia.Base/Media/DashStyle.cs index 4749bfa401..2529b9317d 100644 --- a/src/Avalonia.Base/Media/DashStyle.cs +++ b/src/Avalonia.Base/Media/DashStyle.cs @@ -44,6 +44,8 @@ namespace Avalonia.Media /// /// The dashes collection. /// The dash sequence offset. + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1012", + Justification = "Collection properties shouldn't be set with SetCurrentValue.")] public DashStyle(IEnumerable? dashes, double offset) { Dashes = (dashes as AvaloniaList) ?? new AvaloniaList(dashes ?? Array.Empty()); diff --git a/src/Avalonia.Base/Media/GradientBrush.cs b/src/Avalonia.Base/Media/GradientBrush.cs index e1654a01b2..971d4fdd58 100644 --- a/src/Avalonia.Base/Media/GradientBrush.cs +++ b/src/Avalonia.Base/Media/GradientBrush.cs @@ -38,6 +38,8 @@ namespace Avalonia.Media /// /// Initializes a new instance of the class. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1012", + Justification = "Collection properties shouldn't be set with SetCurrentValue.")] public GradientBrush() { this.GradientStops = new GradientStops(); diff --git a/src/Avalonia.Base/Media/PolyLineSegment.cs b/src/Avalonia.Base/Media/PolyLineSegment.cs index 5c48c11e19..276bb66a4a 100644 --- a/src/Avalonia.Base/Media/PolyLineSegment.cs +++ b/src/Avalonia.Base/Media/PolyLineSegment.cs @@ -28,6 +28,8 @@ namespace Avalonia.Media /// /// Initializes a new instance of the class. /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1012", + Justification = "Collection properties shouldn't be set with SetCurrentValue.")] public PolyLineSegment() { Points = new Points(); diff --git a/src/Avalonia.Base/Media/TransformGroup.cs b/src/Avalonia.Base/Media/TransformGroup.cs index 0465efd5a5..ae5e54c414 100644 --- a/src/Avalonia.Base/Media/TransformGroup.cs +++ b/src/Avalonia.Base/Media/TransformGroup.cs @@ -11,6 +11,8 @@ namespace Avalonia.Media public static readonly StyledProperty ChildrenProperty = AvaloniaProperty.Register(nameof(Children)); + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1012", + Justification = "Collection properties shouldn't be set with SetCurrentValue.")] public TransformGroup() { Children = new Transforms(); diff --git a/src/Avalonia.Controls/Documents/Span.cs b/src/Avalonia.Controls/Documents/Span.cs index d3565cbdd5..7931ecbbde 100644 --- a/src/Avalonia.Controls/Documents/Span.cs +++ b/src/Avalonia.Controls/Documents/Span.cs @@ -18,6 +18,8 @@ namespace Avalonia.Controls.Documents AvaloniaProperty.Register( nameof(Inlines)); + [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1012", + Justification = "Collection properties shouldn't be set with SetCurrentValue.")] public Span() { Inlines = new InlineCollection From 3da148f5c2732622db5eaeec0906416900635c49 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Wed, 19 Apr 2023 00:33:44 -0400 Subject: [PATCH 13/80] Fix analyzers nuget package --- nukebuild/numerge.config | 5 +++++ .../Avalonia.Analyzers.csproj | 19 ++++++++++++------- .../GeneratorContextExtensions.cs | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/nukebuild/numerge.config b/nukebuild/numerge.config index 09f22ec527..71b77bee93 100644 --- a/nukebuild/numerge.config +++ b/nukebuild/numerge.config @@ -16,6 +16,11 @@ "Id": "Avalonia.Generators", "IgnoreMissingFrameworkBinaries": true, "DoNotMergeDependencies": true + }, + { + "Id": "Avalonia.Analyzers", + "IgnoreMissingFrameworkBinaries": true, + "DoNotMergeDependencies": true } ] } diff --git a/src/tools/Avalonia.Analyzers/Avalonia.Analyzers.csproj b/src/tools/Avalonia.Analyzers/Avalonia.Analyzers.csproj index 39eaab1289..c27801db61 100644 --- a/src/tools/Avalonia.Analyzers/Avalonia.Analyzers.csproj +++ b/src/tools/Avalonia.Analyzers/Avalonia.Analyzers.csproj @@ -1,17 +1,22 @@  - netstandard2.0 - enable + false + Avalonia.Analyzers true + true + true - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + + + + + diff --git a/src/tools/Avalonia.Generators/GeneratorContextExtensions.cs b/src/tools/Avalonia.Generators/GeneratorContextExtensions.cs index d057e8732e..3e4426e6bb 100644 --- a/src/tools/Avalonia.Generators/GeneratorContextExtensions.cs +++ b/src/tools/Avalonia.Generators/GeneratorContextExtensions.cs @@ -20,7 +20,7 @@ internal static class GeneratorContextExtensions public static void ReportNameGeneratorUnhandledError(this GeneratorExecutionContext context, Exception error) => context.Report(UnhandledErrorDescriptorId, "Unhandled exception occured while generating typed Name references. " + - "Please file an issue: https://github.com/avaloniaui/Avalonia.Generators", + "Please file an issue: https://github.com/avaloniaui/Avalonia", error.ToString()); public static void ReportNameGeneratorInvalidType(this GeneratorExecutionContext context, string typeName) => From 8df3b340322c9e185e723cf1f930aefef963af86 Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Wed, 19 Apr 2023 16:59:09 +0200 Subject: [PATCH 14/80] Add TextEndOfLine runs to TextBounds.TextRunBounds --- .../Media/TextFormatting/TextLineImpl.cs | 20 +++++++++++--- .../Media/TextFormatting/TextLineTests.cs | 27 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs index 3264d5e88a..935347ed85 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs @@ -698,7 +698,7 @@ namespace Avalonia.Media.TextFormatting i = lastRunIndex; //Possible overlap at runs of different direction - if (directionalWidth == 0) + if (directionalWidth == 0 && i < _textRuns.Length - 1) { //In case a run only contains a linebreak we don't want to skip it. if (currentRun is ShapedTextRun shaped) @@ -844,7 +844,7 @@ namespace Avalonia.Media.TextFormatting i = firstRunIndex; //Possible overlap at runs of different direction - if (directionalWidth == 0) + if (directionalWidth == 0 && i > 0) { //In case a run only contains a linebreak we don't want to skip it. if (currentRun is ShapedTextRun shaped) @@ -860,8 +860,8 @@ namespace Avalonia.Media.TextFormatting } } - TextBounds? textBounds = null; int coveredLength; + TextBounds? textBounds; switch (currentDirection) { @@ -942,6 +942,13 @@ namespace Avalonia.Media.TextFormatting new TextRunBounds( new Rect(startX, 0, drawableTextRun.Size.Width, Height), currentPosition, currentRun.Length, currentRun)); } + else + { + //Add potential TextEndOfParagraph + textRunBounds.Add( + new TextRunBounds( + new Rect(endX, 0, 0, Height), currentPosition, currentRun.Length, currentRun)); + } currentPosition += currentRun.Length; @@ -1007,6 +1014,13 @@ namespace Avalonia.Media.TextFormatting endX += drawableTextRun.Size.Width; } + else + { + //Add potential TextEndOfParagraph + textRunBounds.Add( + new TextRunBounds( + new Rect(endX, 0, 0, Height), currentPosition, currentRun.Length, currentRun)); + } currentPosition += currentRun.Length; diff --git a/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs b/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs index d605ecbfda..1a39dd5223 100644 --- a/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs +++ b/tests/Avalonia.Skia.UnitTests/Media/TextFormatting/TextLineTests.cs @@ -1021,6 +1021,33 @@ namespace Avalonia.Skia.UnitTests.Media.TextFormatting } } + [Fact] + public void Should_GetTextBounds_With_EndOfParagraph() + { + var text = "abc"; + + using (Start()) + { + var defaultProperties = new GenericTextRunProperties(Typeface.Default); + var textSource = new SingleBufferTextSource(text, defaultProperties, true); + + var formatter = new TextFormatterImpl(); + + var textLine = + formatter.FormatLine(textSource, 0, double.PositiveInfinity, + new GenericTextParagraphProperties(FlowDirection.LeftToRight, TextAlignment.Left, + true, true, defaultProperties, TextWrapping.NoWrap, 0, 0, 0)); + + var textBounds = textLine.GetTextBounds(3, 1); + + Assert.Equal(1, textBounds.Count); + + var firstBounds = textBounds.First(); + + Assert.True(firstBounds.TextRunBounds.Count > 0); + } + } + private class FixedRunsTextSource : ITextSource { private readonly IReadOnlyList _textRuns; From bf06f075cbe851e4115928098167ca9600001a05 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Fri, 21 Apr 2023 02:00:40 -0400 Subject: [PATCH 15/80] Fix crash on Cursor.Parse in DevTools --- src/Avalonia.Base/Input/Cursor.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Base/Input/Cursor.cs b/src/Avalonia.Base/Input/Cursor.cs index c555087879..49660e508e 100644 --- a/src/Avalonia.Base/Input/Cursor.cs +++ b/src/Avalonia.Base/Input/Cursor.cs @@ -42,19 +42,21 @@ namespace Avalonia.Input public class Cursor : IDisposable { public static readonly Cursor Default = new Cursor(StandardCursorType.Arrow); + private string _name; - internal Cursor(ICursorImpl platformImpl) + private Cursor(ICursorImpl platformImpl, string name) { PlatformImpl = platformImpl; + _name = name; } public Cursor(StandardCursorType cursorType) - : this(GetCursorFactory().GetCursor(cursorType)) + : this(GetCursorFactory().GetCursor(cursorType), cursorType.ToString()) { } public Cursor(IBitmap cursor, PixelPoint hotSpot) - : this(GetCursorFactory().CreateCursor(cursor.PlatformImpl.Item, hotSpot)) + : this(GetCursorFactory().CreateCursor(cursor.PlatformImpl.Item, hotSpot), "BitmapCursor") { } @@ -73,5 +75,10 @@ namespace Avalonia.Input { return AvaloniaLocator.Current.GetRequiredService(); } + + public override string ToString() + { + return _name; + } } } From 8ab2aa7dc922e02da61832c0aeeff27033fbbf75 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Fri, 21 Apr 2023 02:01:42 -0400 Subject: [PATCH 16/80] Add context flyout to the dev tools tree --- .../ViewModels/TreePageViewModel.cs | 107 ++++++++++++++++++ .../Diagnostics/Views/TreePageView.xaml | 14 +++ .../Diagnostics/Views/TreePageView.xaml.cs | 11 ++ 3 files changed, 132 insertions(+) diff --git a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs index e916995bae..4e8b4c66a2 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/ViewModels/TreePageViewModel.cs @@ -1,5 +1,11 @@ using System; +using System.Collections.Generic; +using System.Linq; using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.LogicalTree; +using Avalonia.Metadata; +using Avalonia.Styling; using Avalonia.VisualTree; namespace Avalonia.Diagnostics.ViewModels @@ -21,6 +27,8 @@ namespace Avalonia.Diagnostics.ViewModels SettersFilter.RefreshFilter += (s, e) => Details?.UpdateStyleFilters(); } + public event EventHandler? ClipboardCopyRequested; + public MainViewModel MainView { get; } public FilterViewModel PropertiesFilter { get; } @@ -106,6 +114,105 @@ namespace Avalonia.Diagnostics.ViewModels } } + public void CopySelector() + { + var currentVisual = SelectedNode?.Visual as Visual; + if (currentVisual is not null) + { + var selector = GetVisualSelector(currentVisual); + + ClipboardCopyRequested?.Invoke(this, selector); + } + } + + public void CopySelectorFromTemplateParent() + { + var parts = new List(); + + var currentVisual = SelectedNode?.Visual as Visual; + while (currentVisual is not null) + { + parts.Add(GetVisualSelector(currentVisual)); + + currentVisual = currentVisual.TemplatedParent as Visual; + } + + if (parts.Any()) + { + parts.Reverse(); + var selector = string.Join(" /template/ ", parts); + + ClipboardCopyRequested?.Invoke(this, selector); + } + } + + public void ExpandRecursively() + { + if (SelectedNode is { } selectedNode) + { + ExpandNode(selectedNode); + + var stack = new Stack(); + stack.Push(selectedNode); + + while (stack.Count > 0) + { + var item = stack.Pop(); + item.IsExpanded = true; + foreach (var child in item.Children) + { + stack.Push(child); + } + } + } + } + + public void CollapseChildren() + { + if (SelectedNode is { } selectedNode) + { + var stack = new Stack(); + stack.Push(selectedNode); + + while (stack.Count > 0) + { + var item = stack.Pop(); + item.IsExpanded = false; + foreach (var child in item.Children) + { + stack.Push(child); + } + } + } + } + + public void CaptureNodeScreenshot() + { + MainView.Shot(null); + } + + public void BringIntoView() + { + (SelectedNode?.Visual as Control)?.BringIntoView(); + } + + + public void Focus() + { + (SelectedNode?.Visual as Control)?.Focus(); + } + + private static string GetVisualSelector(Visual visual) + { + var name = string.IsNullOrEmpty(visual.Name) ? "" : $"#{visual.Name}"; + var classes = string.Concat(visual.Classes + .Where(c => !c.StartsWith(":")) + .Select(c => '.' + c)); + var typeName = ((IStyleable)visual).StyleKey.Name; + + return $"{typeName}{name}{classes}"; + } + private void ExpandNode(TreeNode? node) { if (node != null) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml index 9ffc301dc1..ecdd46dd74 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml @@ -26,6 +26,20 @@ + + + + + + + + + + + + + + diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs index 1a4bb6170a..66be6b5041 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics; using System.Linq; using Avalonia.Controls; @@ -38,6 +39,16 @@ namespace Avalonia.Diagnostics.Views AdornerLayer.SetIsClipEnabled(_adorner, false); } + protected override void OnDataContextChanged(EventArgs e) + { + base.OnDataContextChanged(e); + + ((TreePageViewModel)DataContext!).ClipboardCopyRequested += (sender, s) => + { + TopLevel.GetTopLevel(this)?.Clipboard?.SetTextAsync(s); + }; + } + protected void AddAdorner(object? sender, PointerEventArgs e) { var node = (TreeNode?)((Control)sender!).DataContext; From 845c220c153d2a1ce832ddd0f566b1779e9b94b0 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 21 Apr 2023 19:56:43 +0100 Subject: [PATCH 17/80] Add avalonia version property to nuget package. --- packages/Avalonia/Avalonia.csproj | 33 +++++++++++++++++++++++++++++++ packages/Avalonia/Avalonia.props | 1 + 2 files changed, 34 insertions(+) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index f21d6fefb4..4cd4983b55 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -5,6 +5,7 @@ + all @@ -60,4 +61,36 @@ + + + + + + + + + + + + " + + "" + Version + "" + + ""); +]]> + + + + + + + $(IntermediateOutputPath)/AvaloniaVersion.props + + + + + true + build + + + diff --git a/packages/Avalonia/Avalonia.props b/packages/Avalonia/Avalonia.props index 2334aa91bc..37263a07ed 100644 --- a/packages/Avalonia/Avalonia.props +++ b/packages/Avalonia/Avalonia.props @@ -7,6 +7,7 @@ + From 6e2dc88622d791b405dea9459003e7b20e24af95 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 21 Apr 2023 20:10:24 +0100 Subject: [PATCH 18/80] add UsedAvaloniaProducts property --- packages/Avalonia/Avalonia.props | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/Avalonia/Avalonia.props b/packages/Avalonia/Avalonia.props index 37263a07ed..a2da228887 100644 --- a/packages/Avalonia/Avalonia.props +++ b/packages/Avalonia/Avalonia.props @@ -4,6 +4,7 @@ $(MSBuildThisFileDirectory)\..\tools\net461\designer\Avalonia.Designer.HostApp.exe $(MSBuildThisFileDirectory)\..\tools\netstandard2.0\Avalonia.Build.Tasks.dll false + $(UsedAvaloniaProducts);AvaloniaUI From 6b13c81527796fd1be7792badd0ce1faadf6e222 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 22 Apr 2023 00:42:43 +0200 Subject: [PATCH 19/80] Raise WindowBase.Resized before SizeChanged. --- src/Avalonia.Controls/WindowBase.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/WindowBase.cs b/src/Avalonia.Controls/WindowBase.cs index c2523207e4..463eda4f3c 100644 --- a/src/Avalonia.Controls/WindowBase.cs +++ b/src/Avalonia.Controls/WindowBase.cs @@ -232,14 +232,16 @@ namespace Avalonia.Controls { FrameSize = PlatformImpl?.FrameSize; - if (ClientSize != clientSize) + var clientSizeChanged = ClientSize != clientSize; + + ClientSize = clientSize; + OnResized(new WindowResizedEventArgs(clientSize, reason)); + + if (clientSizeChanged) { - ClientSize = clientSize; LayoutManager.ExecuteLayoutPass(); Renderer.Resized(clientSize); } - - OnResized(new WindowResizedEventArgs(clientSize, reason)); } /// From 1ff87d8dd59819dc937ab9d601f9e67de43f496c Mon Sep 17 00:00:00 2001 From: Sergey Mikolaitis Date: Sat, 22 Apr 2023 02:04:59 +0300 Subject: [PATCH 20/80] [Input] [MacOS] fix timestamp overflow on objC side --- native/Avalonia.Native/src/OSX/AvnView.mm | 2 +- native/Avalonia.Native/src/OSX/AvnWindow.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/native/Avalonia.Native/src/OSX/AvnView.mm b/native/Avalonia.Native/src/OSX/AvnView.mm index 6d1ff7cf12..9a43d9ddcf 100644 --- a/native/Avalonia.Native/src/OSX/AvnView.mm +++ b/native/Avalonia.Native/src/OSX/AvnView.mm @@ -275,7 +275,7 @@ delta.Y = [event deltaY]; } - uint32 timestamp = static_cast([event timestamp] * 1000); + uint64 timestamp = static_cast([event timestamp] * 1000); auto modifiers = [self getModifiers:[event modifierFlags]]; if(type != Move || diff --git a/native/Avalonia.Native/src/OSX/AvnWindow.mm b/native/Avalonia.Native/src/OSX/AvnWindow.mm index 16e1486acc..ef50cdab84 100644 --- a/native/Avalonia.Native/src/OSX/AvnWindow.mm +++ b/native/Avalonia.Native/src/OSX/AvnWindow.mm @@ -460,7 +460,7 @@ auto point = [self translateLocalPoint:avnPoint]; AvnVector delta = { 0, 0 }; - _parent->BaseEvents->RawMouseEvent(NonClientLeftButtonDown, static_cast([event timestamp] * 1000), AvnInputModifiersNone, point, delta); + _parent->BaseEvents->RawMouseEvent(NonClientLeftButtonDown, static_cast([event timestamp] * 1000), AvnInputModifiersNone, point, delta); } if(!_isTransitioningToFullScreen) From bf8bf14c549745a2a5ac495ad743a3e544b915b2 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sun, 23 Apr 2023 17:31:47 +0100 Subject: [PATCH 21/80] write the version number more simply. --- packages/Avalonia/Avalonia.csproj | 35 +++++-------------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index 4cd4983b55..8d56b557b3 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -5,7 +5,7 @@ - + all @@ -62,35 +62,10 @@ - - - - - - - - - - - " + - "" + Version + "" + - ""); -]]> - - - - - - $(IntermediateOutputPath)/AvaloniaVersion.props - - - - - true - build - - + From 51ba74fb4687a06daf9fef24ca950c2e0066e438 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sun, 23 Apr 2023 17:57:09 +0100 Subject: [PATCH 22/80] fix build. --- packages/Avalonia/Avalonia.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index 8d56b557b3..39120f64f5 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -63,6 +63,9 @@ + + $(IntermediateOutputPath)/AvaloniaVersion.props + Date: Sun, 23 Apr 2023 18:29:28 +0100 Subject: [PATCH 23/80] fix including version file in nuget package. --- packages/Avalonia/Avalonia.csproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index 39120f64f5..db5721b0ab 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -70,5 +70,11 @@ File="$(PackageVersionPropsPath)" Overwrite="true" Lines="<Project><PropertyGroup><AvaloniaMainPackageVersion>$(PackageVersion)</AvaloniaMainPackageVersion></PropertyGroup></Project>" /> + + + true + build + + From 3c85bcc15e9f8a3693c271b142c45f518104a3f9 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sun, 23 Apr 2023 21:41:58 +0100 Subject: [PATCH 24/80] update. --- packages/Avalonia/Avalonia.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index db5721b0ab..a024e0155a 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -5,7 +5,7 @@ - + all From ce8c3be43fa40d23f9aecb76598c4064adcac640 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 24 Apr 2023 10:45:20 +0100 Subject: [PATCH 25/80] update --- packages/Avalonia/Avalonia.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index a024e0155a..26bf7dbeaa 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -5,7 +5,7 @@ - + all From 0921a980671a33ef9d94c3ce7f8134d2ab8a69d7 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Mon, 24 Apr 2023 11:46:22 +0200 Subject: [PATCH 26/80] Use latest Tmds.DBus version. --- src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj b/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj index d8162c0486..4805c3a034 100644 --- a/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj +++ b/src/Avalonia.FreeDesktop/Avalonia.FreeDesktop.csproj @@ -12,7 +12,7 @@ - + From 990b1341597e2a54fee514741953b30fa4343334 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 24 Apr 2023 11:54:54 +0100 Subject: [PATCH 27/80] update --- packages/Avalonia/Avalonia.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index 26bf7dbeaa..dcef4cb7c8 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -5,7 +5,7 @@ - + all From 6b4d286f4318e3ebd18ffa0a7f9190bf66bd6e96 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 24 Apr 2023 13:53:02 +0100 Subject: [PATCH 28/80] update --- packages/Avalonia/Avalonia.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index dcef4cb7c8..f309a5b711 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -5,7 +5,7 @@ - + all From 66f07356bf4ef2a876281f58b3b45996fdf09e6d Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 24 Apr 2023 17:00:38 +0100 Subject: [PATCH 29/80] update. --- packages/Avalonia/Avalonia.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index f309a5b711..27b9453103 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -5,7 +5,7 @@ - + all From 06b7515b48e284750872875e2cd53d1f77c2284c Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 24 Apr 2023 18:55:19 +0200 Subject: [PATCH 30/80] Added failing test for #11076. --- .../Layout/LayoutManagerTests.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs b/tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs index 9f13520086..09f78c5a6c 100644 --- a/tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs +++ b/tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs @@ -59,6 +59,29 @@ namespace Avalonia.Base.UnitTests.Layout Assert.False(control.Arranged); } + [Fact] + public void Lays_Out_Descendents_That_Were_Invalidated_While_Ancestor_Was_Not_Visible() + { + // Issue #11076 + var control = new LayoutTestControl(); + var parent = new Decorator { Child = control }; + var grandparent = new Decorator { Child = parent }; + var root = new LayoutTestRoot { Child = grandparent }; + + root.LayoutManager.ExecuteInitialLayoutPass(); + + grandparent.IsVisible = false; + control.InvalidateMeasure(); + root.LayoutManager.ExecuteInitialLayoutPass(); + + grandparent.IsVisible = true; + + root.LayoutManager.ExecuteLayoutPass(); + + Assert.True(control.IsMeasureValid); + Assert.True(control.IsArrangeValid); + } + [Fact] public void Arranges_InvalidateArranged_Control() { From a3917d6b73b703c739ff888cee5db471e05c4ec7 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 24 Apr 2023 18:05:02 +0100 Subject: [PATCH 31/80] update --- packages/Avalonia/Avalonia.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Avalonia/Avalonia.csproj b/packages/Avalonia/Avalonia.csproj index 27b9453103..547af5d0dc 100644 --- a/packages/Avalonia/Avalonia.csproj +++ b/packages/Avalonia/Avalonia.csproj @@ -5,7 +5,7 @@ - + all From 41d76f256b12501c698c4a0d4142688c1c2e210f Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 24 Apr 2023 18:13:47 -0400 Subject: [PATCH 32/80] Add AvaloniaListAttribute --- .../Metadata/AvaloniaListAttribute.cs | 23 +++++++++++++++++++ .../AvaloniaXamlIlLanguageParseIntrinsics.cs | 14 +++++++++++ .../AvaloniaXamlIlWellKnownTypes.cs | 2 ++ .../Avalonia.Markup.Xaml.Loader/xamlil.github | 2 +- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/Avalonia.Base/Metadata/AvaloniaListAttribute.cs diff --git a/src/Avalonia.Base/Metadata/AvaloniaListAttribute.cs b/src/Avalonia.Base/Metadata/AvaloniaListAttribute.cs new file mode 100644 index 0000000000..d523808d32 --- /dev/null +++ b/src/Avalonia.Base/Metadata/AvaloniaListAttribute.cs @@ -0,0 +1,23 @@ +using System; + +namespace Avalonia.Metadata; + +/// +/// Defines how compiler should split avalonia list string value before parsing individual items. +/// +[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] +public sealed class AvaloniaListAttribute : Attribute +{ + /// + /// Separator used to split input string. + /// Default value is ','. + /// + public string[]? Separators { get; init; } + + /// + /// Split options used to split input string. + /// Default value is RemoveEmptyEntries with TrimEntries. + /// + // StringSplitOptions.TrimEntries = 2, but only on net6 target. + public StringSplitOptions SplitOptions { get; init; } = StringSplitOptions.RemoveEmptyEntries | (StringSplitOptions)2; +} diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs index cd005ce24d..6c7b04dbfb 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs @@ -337,6 +337,20 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions var separators = new[] { "," }; var splitOptions = StringSplitOptions.RemoveEmptyEntries | trimOption; + var attribute = type.GetAllCustomAttributes().FirstOrDefault(a => a.Type == types.AvaloniaListAttribute); + if (attribute is not null) + { + if (attribute.Properties.TryGetValue("Separators", out var separatorsArray)) + { + separators = ((Array)separatorsArray)?.OfType().ToArray(); + } + + if (attribute.Properties.TryGetValue("SplitOptions", out var splitOptionsObj)) + { + splitOptions = (StringSplitOptions)splitOptionsObj; + } + } + items = text.Split(separators, splitOptions ^ trimOption); // Compiler targets netstandard, so we need to emulate StringSplitOptions.TrimEntries, if it was requested. if (splitOptions.HasFlag(trimOption)) diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs index 8ab84f4615..b5c0c7734d 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs @@ -33,6 +33,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers public IXamlType InheritDataTypeFromItemsAttribute { get; } public IXamlType MarkupExtensionOptionAttribute { get; } public IXamlType MarkupExtensionDefaultOptionAttribute { get; } + public IXamlType AvaloniaListAttribute { get; } public IXamlType AvaloniaList { get; } public IXamlType OnExtensionType { get; } public IXamlType UnsetValueType { get; } @@ -143,6 +144,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers InheritDataTypeFromItemsAttribute = cfg.TypeSystem.GetType("Avalonia.Metadata.InheritDataTypeFromItemsAttribute"); MarkupExtensionOptionAttribute = cfg.TypeSystem.GetType("Avalonia.Metadata.MarkupExtensionOptionAttribute"); MarkupExtensionDefaultOptionAttribute = cfg.TypeSystem.GetType("Avalonia.Metadata.MarkupExtensionDefaultOptionAttribute"); + AvaloniaListAttribute = cfg.TypeSystem.GetType("Avalonia.Metadata.AvaloniaListAttribute"); AvaloniaList = cfg.TypeSystem.GetType("Avalonia.Collections.AvaloniaList`1"); OnExtensionType = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.On"); AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, AvaloniaObject, diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github b/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github index 5d1025f30d..e5254eb1b2 160000 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github @@ -1 +1 @@ -Subproject commit 5d1025f30d0ed6d8f419d82959c148276301f393 +Subproject commit e5254eb1b2017f78a92acd466c8fa1e47401056b From 89e1680501859c0f31fa4da65b2f5c28e3205e82 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 24 Apr 2023 18:13:55 -0400 Subject: [PATCH 33/80] Fix DefinitionList parsing --- src/Avalonia.Controls/DefinitionList.cs | 2 ++ .../Xaml/BasicTests.cs | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/Avalonia.Controls/DefinitionList.cs b/src/Avalonia.Controls/DefinitionList.cs index c850647bf4..63a54731e0 100644 --- a/src/Avalonia.Controls/DefinitionList.cs +++ b/src/Avalonia.Controls/DefinitionList.cs @@ -1,9 +1,11 @@ using System.Collections; using System.Collections.Specialized; using Avalonia.Collections; +using Avalonia.Metadata; namespace Avalonia.Controls { + [AvaloniaList(Separators = new [] { ",", " " })] public abstract class DefinitionList : AvaloniaList where T : DefinitionBase { public DefinitionList() diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs index 421ed2c979..70541b6196 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs @@ -261,6 +261,37 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml var grid = AvaloniaRuntimeXamlLoader.Parse(xaml); + Assert.Equal(4, grid.ColumnDefinitions.Count); + Assert.Equal(4, grid.RowDefinitions.Count); + + var expected1 = new GridLength(100); + var expected2 = GridLength.Auto; + var expected3 = new GridLength(1, GridUnitType.Star); + var expected4 = new GridLength(100, GridUnitType.Star); + + Assert.Equal(expected1, grid.ColumnDefinitions[0].Width); + Assert.Equal(expected2, grid.ColumnDefinitions[1].Width); + Assert.Equal(expected3, grid.ColumnDefinitions[2].Width); + Assert.Equal(expected4, grid.ColumnDefinitions[3].Width); + + Assert.Equal(expected1, grid.RowDefinitions[0].Height); + Assert.Equal(expected2, grid.RowDefinitions[1].Height); + Assert.Equal(expected3, grid.RowDefinitions[2].Height); + Assert.Equal(expected4, grid.RowDefinitions[3].Height); + } + + [Fact] + public void Grid_Row_Col_Definitions_Are_Parsed_Space_Delimiter() + { + var xaml = @" + +"; + + var grid = AvaloniaRuntimeXamlLoader.Parse(xaml); + + Assert.Equal(4, grid.ColumnDefinitions.Count); Assert.Equal(4, grid.RowDefinitions.Count); From decf80cb7736c4e099b10703df7cb5dce84c8d2a Mon Sep 17 00:00:00 2001 From: Max Katz Date: Tue, 25 Apr 2023 00:47:14 -0400 Subject: [PATCH 34/80] Adds RenderScaling and DesktopScaling back to the public API together with ScalingChanged --- src/Avalonia.Controls/TopLevel.cs | 8 +++++++- src/Avalonia.Controls/WindowBase.cs | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index 8a1cdf3f80..881474c761 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -285,6 +285,11 @@ namespace Avalonia.Controls /// public event EventHandler? Closed; + /// + /// Gets or sets a method called when the TopLevel's scaling changes. + /// + public event EventHandler? ScalingChanged; + /// /// Gets or sets the client size of the window. /// @@ -428,7 +433,7 @@ namespace Avalonia.Controls double ILayoutRoot.LayoutScaling => PlatformImpl?.RenderScaling ?? 1; /// - double IRenderRoot.RenderScaling => PlatformImpl?.RenderScaling ?? 1; + public double RenderScaling => PlatformImpl?.RenderScaling ?? 1; IStyleHost IStyleHost.StylingParent => _globalStyles!; @@ -590,6 +595,7 @@ namespace Avalonia.Controls protected virtual void HandleScalingChanged(double scaling) { LayoutHelper.InvalidateSelfAndChildrenMeasure(this); + ScalingChanged?.Invoke(this, EventArgs.Empty); } private static bool TransparencyLevelsMatch (WindowTransparencyLevel requested, WindowTransparencyLevel received) diff --git a/src/Avalonia.Controls/WindowBase.cs b/src/Avalonia.Controls/WindowBase.cs index c2523207e4..d640a0c2dc 100644 --- a/src/Avalonia.Controls/WindowBase.cs +++ b/src/Avalonia.Controls/WindowBase.cs @@ -116,6 +116,11 @@ namespace Avalonia.Controls set { SetValue(TopmostProperty, value); } } + /// + /// Gets the scaling factor for Window positioning and sizing. + /// + public double DesktopScaling => PlatformImpl?.DesktopScaling ?? 1; + /// /// Activates the window. /// From c2220039dadd13583f871e592ebf6c7d04254919 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 24 Apr 2023 18:56:03 +0200 Subject: [PATCH 35/80] Re-layout descendants when made effectively visible. Fixes #11076. --- src/Avalonia.Base/Layout/Layoutable.cs | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Base/Layout/Layoutable.cs b/src/Avalonia.Base/Layout/Layoutable.cs index ed88b73149..08f327d048 100644 --- a/src/Avalonia.Base/Layout/Layoutable.cs +++ b/src/Avalonia.Base/Layout/Layoutable.cs @@ -776,10 +776,24 @@ namespace Avalonia.Layout // All changes to visibility cause the parent element to be notified. this.GetVisualParent()?.ChildDesiredSizeChanged(this); - // We only invalidate outselves when visibility is changed to true. if (change.GetNewValue()) { + // We only invalidate ourselves when visibility is changed to true. InvalidateMeasure(); + + // If any descendant had its measure/arrange invalidated while we were hidden, + // they will need to to be registered with the layout manager now that they + // are again effectively visible. If IsEffectivelyVisible becomes an observable + // property then we can piggy-pack on that; for the moment we do this manually. + if (VisualRoot is ILayoutRoot layoutRoot) + { + var count = VisualChildren.Count; + + for (var i = 0; i < count; ++i) + { + (VisualChildren[i] as Layoutable)?.AncestorBecameVisible(layoutRoot.LayoutManager); + } + } } } } @@ -804,6 +818,30 @@ namespace Avalonia.Layout InvalidateMeasure(); } + private void AncestorBecameVisible(ILayoutManager layoutManager) + { + if (!IsVisible) + return; + + if (!IsMeasureValid) + { + layoutManager.InvalidateMeasure(this); + InvalidateVisual(); + } + else if (!IsArrangeValid) + { + layoutManager.InvalidateArrange(this); + InvalidateVisual(); + } + + var count = VisualChildren.Count; + + for (var i = 0; i < count; ++i) + { + (VisualChildren[i] as Layoutable)?.AncestorBecameVisible(layoutManager); + } + } + /// /// Called when the layout manager raises a LayoutUpdated event. /// From b8fed4cbeafb10c4e2ccca068a9ace9c7249fd43 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 24 Apr 2023 19:03:26 +0200 Subject: [PATCH 36/80] Remove hack from VirtualizingStackPanel. No longer needed since layout invalidation was fixed in last commit. --- .../VirtualizingStackPanel.cs | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/src/Avalonia.Controls/VirtualizingStackPanel.cs b/src/Avalonia.Controls/VirtualizingStackPanel.cs index 77268c7831..071ac95f45 100644 --- a/src/Avalonia.Controls/VirtualizingStackPanel.cs +++ b/src/Avalonia.Controls/VirtualizingStackPanel.cs @@ -556,7 +556,6 @@ namespace Avalonia.Controls GetItemIsOwnContainer(items, index) ?? GetRecycledElement(items, index) ?? CreateElement(items, index); - InvalidateHack(e); return e; } @@ -705,39 +704,6 @@ namespace Avalonia.Controls } } - private static void InvalidateHack(Control c) - { - bool HasInvalidations(Control c) - { - if (!c.IsMeasureValid) - return true; - - for (var i = 0; i < c.VisualChildren.Count; ++i) - { - if (c.VisualChildren[i] is Control child) - { - if (!child.IsMeasureValid || HasInvalidations(child)) - return true; - } - } - - return false; - } - - void Invalidate(Control c) - { - c.InvalidateMeasure(); - for (var i = 0; i < c.VisualChildren.Count; ++i) - { - if (c.VisualChildren[i] is Control child) - Invalidate(child); - } - } - - if (HasInvalidations(c)) - Invalidate(c); - } - private void OnUnrealizedFocusedElementLostFocus(object? sender, RoutedEventArgs e) { if (_unrealizedFocusedElement is null || sender != _unrealizedFocusedElement) From 109c05aeab917174f4f60775357384b02ff9c43e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 24 Apr 2023 20:57:55 +0200 Subject: [PATCH 37/80] Increase max number of permitted layout attempts. And log a message when a control was skipped due to a layout cycle. --- src/Avalonia.Base/Layout/LayoutManager.cs | 2 +- src/Avalonia.Base/Layout/LayoutQueue.cs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Base/Layout/LayoutManager.cs b/src/Avalonia.Base/Layout/LayoutManager.cs index 94955a18ae..747ee1c082 100644 --- a/src/Avalonia.Base/Layout/LayoutManager.cs +++ b/src/Avalonia.Base/Layout/LayoutManager.cs @@ -17,7 +17,7 @@ namespace Avalonia.Layout /// public class LayoutManager : ILayoutManager, IDisposable { - private const int MaxPasses = 3; + private const int MaxPasses = 10; private readonly Layoutable _owner; private readonly LayoutQueue _toMeasure = new LayoutQueue(v => !v.IsMeasureValid); private readonly LayoutQueue _toArrange = new LayoutQueue(v => !v.IsArrangeValid); diff --git a/src/Avalonia.Base/Layout/LayoutQueue.cs b/src/Avalonia.Base/Layout/LayoutQueue.cs index 24adeb0793..48efa501f2 100644 --- a/src/Avalonia.Base/Layout/LayoutQueue.cs +++ b/src/Avalonia.Base/Layout/LayoutQueue.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using Avalonia.Logging; namespace Avalonia.Layout { @@ -48,10 +49,21 @@ namespace Avalonia.Layout { _loopQueueInfo.TryGetValue(item, out var info); - if (!info.Active && info.Count < _maxEnqueueCountPerLoop) + if (!info.Active) { - _inner.Enqueue(item); - _loopQueueInfo[item] = new Info() { Active = true, Count = info.Count + 1 }; + if (info.Count < _maxEnqueueCountPerLoop) + { + _inner.Enqueue(item); + _loopQueueInfo[item] = new Info() { Active = true, Count = info.Count + 1 }; + } + else + { + Logger.TryGet(LogEventLevel.Warning, LogArea.Layout)?.Log( + this, + "Layout cycle detected. Item {Item} was enqueued {Count} times.", + item, + info.Count); + } } } From 4ddd83b561dd78036416cbd6c4e11beb74da59f8 Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Tue, 25 Apr 2023 17:46:31 +0200 Subject: [PATCH 38/80] Fix TextBlock Measure/Arrange --- .../Media/TextFormatting/TextLineImpl.cs | 13 ++-------- src/Avalonia.Controls/TextBlock.cs | 26 +++++++++++-------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs index 935347ed85..1234067844 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs @@ -83,7 +83,7 @@ namespace Avalonia.Media.TextFormatting /// public override void Draw(DrawingContext drawingContext, Point lineOrigin) { - var (currentX, currentY) = lineOrigin; + var (currentX, currentY) = lineOrigin + new Point(Start, 0); foreach (var textRun in _textRuns) { @@ -1423,8 +1423,6 @@ namespace Avalonia.Media.TextFormatting var fontMetrics = _paragraphProperties.DefaultTextRunProperties.CachedGlyphTypeface.Metrics; var fontRenderingEmSize = _paragraphProperties.DefaultTextRunProperties.FontRenderingEmSize; var scale = fontRenderingEmSize / fontMetrics.DesignEmHeight; - - var width = 0d; var widthIncludingWhitespace = 0d; var trailingWhitespaceLength = 0; var newLineLength = 0; @@ -1436,13 +1434,6 @@ namespace Avalonia.Media.TextFormatting var lineHeight = _paragraphProperties.LineHeight; - var lastRunIndex = _textRuns.Length - 1; - - if (lastRunIndex > 0 && _textRuns[lastRunIndex] is TextEndOfLine) - { - lastRunIndex--; - } - for (var index = 0; index < _textRuns.Length; index++) { switch (_textRuns[index]) @@ -1500,7 +1491,7 @@ namespace Avalonia.Media.TextFormatting } } - width = widthIncludingWhitespace; + var width = widthIncludingWhitespace; for (var i = _textRuns.Length - 1; i >= 0; i--) { diff --git a/src/Avalonia.Controls/TextBlock.cs b/src/Avalonia.Controls/TextBlock.cs index 19eaaaa0d9..155d7d5f56 100644 --- a/src/Avalonia.Controls/TextBlock.cs +++ b/src/Avalonia.Controls/TextBlock.cs @@ -7,7 +7,6 @@ using Avalonia.Layout; using Avalonia.Media; using Avalonia.Media.TextFormatting; using Avalonia.Metadata; -using Avalonia.Utilities; namespace Avalonia.Controls { @@ -565,7 +564,8 @@ namespace Avalonia.Controls context.FillRectangle(background, new Rect(Bounds.Size)); } - var padding = Padding; + var scale = LayoutHelper.GetLayoutScale(this); + var padding = LayoutHelper.RoundLayoutThickness(Padding, scale, scale); var top = padding.Top; var textHeight = TextLayout.Bounds.Height; @@ -659,7 +659,6 @@ namespace Avalonia.Controls protected override Size MeasureOverride(Size availableSize) { var scale = LayoutHelper.GetLayoutScale(this); - var padding = LayoutHelper.RoundLayoutThickness(Padding, scale, scale); _constraint = availableSize.Deflate(padding); @@ -703,19 +702,24 @@ namespace Avalonia.Controls } } - var measuredSize = TextLayout.Bounds.Size.Inflate(padding); - - return measuredSize; + return TextLayout.Bounds.Size.Inflate(padding); } protected override Size ArrangeOverride(Size finalSize) { - if (HasComplexContent) - { - var scale = LayoutHelper.GetLayoutScale(this); + var scale = LayoutHelper.GetLayoutScale(this); + var padding = LayoutHelper.RoundLayoutThickness(Padding, scale, scale); - var padding = LayoutHelper.RoundLayoutThickness(Padding, scale, scale); + //Fixes: #11019 + if (finalSize.Width < _constraint.Width) + { + _textLayout?.Dispose(); + _textLayout = null; + _constraint = finalSize.Deflate(padding); + } + if (HasComplexContent) + { var currentY = padding.Top; foreach (var textLine in TextLayout.TextLines) @@ -730,7 +734,7 @@ namespace Avalonia.Controls && controlRun.Control is Control control) { control.Arrange( - new Rect(new Point(currentX, currentY), + new Rect(new Point(currentX, currentY), new Size(control.DesiredSize.Width, textLine.Height))); } From ec74cb2dc685e02b2934d12617dbbb32f78da81e Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Tue, 25 Apr 2023 18:30:39 +0200 Subject: [PATCH 39/80] Fix font fallback for control characters --- src/Avalonia.Base/Media/TextFormatting/TextCharacters.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Base/Media/TextFormatting/TextCharacters.cs b/src/Avalonia.Base/Media/TextFormatting/TextCharacters.cs index 253c7075fa..7d4fac337d 100644 --- a/src/Avalonia.Base/Media/TextFormatting/TextCharacters.cs +++ b/src/Avalonia.Base/Media/TextFormatting/TextCharacters.cs @@ -185,7 +185,9 @@ namespace Avalonia.Media.TextFormatting } //Stop at the first missing glyph - if (!currentCodepoint.IsBreakChar && !glyphTypeface.TryGetGlyph(currentCodepoint, out _)) + if (!currentCodepoint.IsBreakChar && + currentCodepoint.GeneralCategory != GeneralCategory.Control && + !glyphTypeface.TryGetGlyph(currentCodepoint, out _)) { break; } From 9f3dbfff6a3e66ac4284edf0332b8168df1d7b7e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 25 Apr 2023 22:31:44 +0200 Subject: [PATCH 40/80] Added docs to clarify difference with SizeChanged. --- src/Avalonia.Controls/WindowBase.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Avalonia.Controls/WindowBase.cs b/src/Avalonia.Controls/WindowBase.cs index 463eda4f3c..0017630a75 100644 --- a/src/Avalonia.Controls/WindowBase.cs +++ b/src/Avalonia.Controls/WindowBase.cs @@ -83,6 +83,19 @@ namespace Avalonia.Controls /// /// Occurs when the window is resized. /// + /// + /// Although this event is similar to the event, they are + /// conceptually different: + /// + /// - is a window-level event, fired when a resize notification arrives + /// from the platform windowing subsystem. The event args contain details of the source of + /// the resize event in the property. This + /// event is raised before layout has been run on the window's content. + /// - is a layout-level event, fired when a layout pass + /// completes on a control. is present on all controls + /// and is fired when the control's size changes for any reason, including a + /// event in the case of a Window. + /// public event EventHandler? Resized; public new IWindowBaseImpl? PlatformImpl => (IWindowBaseImpl?) base.PlatformImpl; From d5b280453caefc4ad6fc0338014fdb34b85a31d1 Mon Sep 17 00:00:00 2001 From: Sergey Mikolaitis Date: Tue, 25 Apr 2023 23:53:52 +0300 Subject: [PATCH 41/80] [MacOS] [Input] use uint64 timestamp in other places, including avn.idl --- native/Avalonia.Native/src/OSX/AvnView.mm | 6 +++--- src/Avalonia.Native/avn.idl | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/native/Avalonia.Native/src/OSX/AvnView.mm b/native/Avalonia.Native/src/OSX/AvnView.mm index 9a43d9ddcf..86bacfb819 100644 --- a/native/Avalonia.Native/src/OSX/AvnView.mm +++ b/native/Avalonia.Native/src/OSX/AvnView.mm @@ -275,7 +275,7 @@ delta.Y = [event deltaY]; } - uint64 timestamp = static_cast([event timestamp] * 1000); + uint64_t timestamp = static_cast([event timestamp] * 1000); auto modifiers = [self getModifiers:[event modifierFlags]]; if(type != Move || @@ -444,7 +444,7 @@ auto key = s_KeyMap[[event keyCode]]; - uint32_t timestamp = static_cast([event timestamp] * 1000); + uint64_t timestamp = static_cast([event timestamp] * 1000); auto modifiers = [self getModifiers:[event modifierFlags]]; if(_parent != nullptr) @@ -657,7 +657,7 @@ [self unmarkText]; - uint32_t timestamp = static_cast([NSDate timeIntervalSinceReferenceDate] * 1000); + uint64_t timestamp = static_cast([NSDate timeIntervalSinceReferenceDate] * 1000); _lastKeyHandled = _parent->BaseEvents->RawTextInputEvent(timestamp, [text UTF8String]); diff --git a/src/Avalonia.Native/avn.idl b/src/Avalonia.Native/avn.idl index 09e9168d8f..a58a00d59d 100644 --- a/src/Avalonia.Native/avn.idl +++ b/src/Avalonia.Native/avn.idl @@ -1,6 +1,7 @@ @clr-namespace Avalonia.Native.Interop @clr-access internal @clr-map bool int +@clr-map u_int64_t ulong @cpp-preamble @@ #pragma once #include "com.h" @@ -583,12 +584,12 @@ interface IAvnWindowBaseEvents : IUnknown void Resized([const] AvnSize& size, AvnPlatformResizeReason reason); void PositionChanged(AvnPoint position); void RawMouseEvent(AvnRawMouseEventType type, - uint timeStamp, + u_int64_t timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta); - bool RawKeyEvent(AvnRawKeyEventType type, uint timeStamp, AvnInputModifiers modifiers, uint key); - bool RawTextInputEvent(uint timeStamp, [const] char* text); + bool RawKeyEvent(AvnRawKeyEventType type, u_int64_t timeStamp, AvnInputModifiers modifiers, uint key); + bool RawTextInputEvent(u_int64_t timeStamp, [const] char* text); void ScalingChanged(double scaling); void RunRenderPriorityJobs(); void LostFocus(); From 6c8afc714c2fa1a4797ab2d2a914c1645f086c00 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 25 Apr 2023 22:54:52 +0200 Subject: [PATCH 42/80] Correctly handle TreeViewPage data context change. Fixes #11120. --- .../Diagnostics/Views/TreePageView.xaml.cs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs index 66be6b5041..b0aea64994 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml.cs @@ -39,16 +39,6 @@ namespace Avalonia.Diagnostics.Views AdornerLayer.SetIsClipEnabled(_adorner, false); } - protected override void OnDataContextChanged(EventArgs e) - { - base.OnDataContextChanged(e); - - ((TreePageViewModel)DataContext!).ClipboardCopyRequested += (sender, s) => - { - TopLevel.GetTopLevel(this)?.Clipboard?.SetTextAsync(s); - }; - } - protected void AddAdorner(object? sender, PointerEventArgs e) { var node = (TreeNode?)((Control)sender!).DataContext; @@ -108,9 +98,27 @@ namespace Avalonia.Diagnostics.Views _currentLayer = null; } + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == DataContextProperty) + { + if (change.GetOldValue() is TreePageViewModel oldViewModel) + oldViewModel.ClipboardCopyRequested -= OnClipboardCopyRequested; + if (change.GetNewValue() is TreePageViewModel newViewModel) + newViewModel.ClipboardCopyRequested += OnClipboardCopyRequested; + } + } + private void InitializeComponent() { AvaloniaXamlLoader.Load(this); } + + private void OnClipboardCopyRequested(object? sender, string e) + { + TopLevel.GetTopLevel(this)?.Clipboard?.SetTextAsync(e); + } } } From 4016da0a2c63d241b888b9682db186dddb631a16 Mon Sep 17 00:00:00 2001 From: Yannick Excoffier Date: Wed, 26 Apr 2023 09:24:17 +0200 Subject: [PATCH 43/80] Set double click on presenter instead of whole header --- src/Avalonia.Controls/TreeViewItem.cs | 6 ++++-- src/Avalonia.Themes.Fluent/Controls/TreeViewItem.xaml | 2 +- src/Avalonia.Themes.Simple/Controls/TreeViewItem.xaml | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/TreeViewItem.cs b/src/Avalonia.Controls/TreeViewItem.cs index 806d7e320b..70ffd218b1 100644 --- a/src/Avalonia.Controls/TreeViewItem.cs +++ b/src/Avalonia.Controls/TreeViewItem.cs @@ -45,6 +45,7 @@ namespace Avalonia.Controls private TreeView? _treeView; private Control? _header; + private Control? _headerPresenter; private int _level; private bool _templateApplied; private bool _deferredBringIntoViewFlag; @@ -255,15 +256,16 @@ namespace Avalonia.Controls protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { - if (_header is InputElement previousInputMethod) + if (_headerPresenter is InputElement previousInputMethod) { previousInputMethod.DoubleTapped -= HeaderDoubleTapped; } _header = e.NameScope.Find("PART_Header"); + _headerPresenter = e.NameScope.Find("PART_HeaderPresenter"); _templateApplied = true; - if (_header is InputElement im) + if (_headerPresenter is InputElement im) { im.DoubleTapped += HeaderDoubleTapped; } diff --git a/src/Avalonia.Themes.Fluent/Controls/TreeViewItem.xaml b/src/Avalonia.Themes.Fluent/Controls/TreeViewItem.xaml index b5f1220bc8..eff3920b12 100644 --- a/src/Avalonia.Themes.Fluent/Controls/TreeViewItem.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/TreeViewItem.xaml @@ -75,7 +75,6 @@ MinHeight="{TemplateBinding MinHeight}" TemplatedControl.IsTemplateFocusTarget="True"> Date: Wed, 26 Apr 2023 11:31:58 +0200 Subject: [PATCH 44/80] Enable source generators in Sandbox. --- samples/Sandbox/MainWindow.axaml.cs | 10 ++-------- samples/Sandbox/Sandbox.csproj | 2 ++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/samples/Sandbox/MainWindow.axaml.cs b/samples/Sandbox/MainWindow.axaml.cs index 23d45edf6a..b8e9f0ff42 100644 --- a/samples/Sandbox/MainWindow.axaml.cs +++ b/samples/Sandbox/MainWindow.axaml.cs @@ -6,17 +6,11 @@ using Avalonia.Win32.WinRT.Composition; namespace Sandbox { - public class MainWindow : Window + public partial class MainWindow : Window { public MainWindow() { - this.InitializeComponent(); - this.AttachDevTools(); - } - - private void InitializeComponent() - { - AvaloniaXamlLoader.Load(this); + InitializeComponent(); } } } diff --git a/samples/Sandbox/Sandbox.csproj b/samples/Sandbox/Sandbox.csproj index f23e391a2a..d2e66988e0 100644 --- a/samples/Sandbox/Sandbox.csproj +++ b/samples/Sandbox/Sandbox.csproj @@ -4,6 +4,7 @@ WinExe net6.0 true + true @@ -17,4 +18,5 @@ + From 582248fb048b49f7f34897e227fae627d34f1e4b Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 26 Apr 2023 12:45:12 +0200 Subject: [PATCH 45/80] Added failing test for #11128. --- .../ItemsControlTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs b/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs index 1a0ea5fdab..5e741cdc1d 100644 --- a/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs @@ -828,6 +828,19 @@ namespace Avalonia.Controls.UnitTests Layout(target); } + [Fact] + public void ItemIsOwnContainer_Content_Should_Not_Be_Cleared_When_Removed() + { + // Issue #11128. + using var app = Start(); + var item = new ContentPresenter { Content = "foo" }; + var target = CreateTarget(items: new[] { item }); + + target.Items.RemoveAt(0); + + Assert.Equal("foo", item.Content); + } + private static ItemsControl CreateTarget( object? dataContext = null, IBinding? displayMemberBinding = null, From c77276d00a7dc3640172aeeb364fe846ae1d1a89 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 26 Apr 2023 12:47:28 +0200 Subject: [PATCH 46/80] Don't clear ItemIsOwnContainer in PanelContainerGenerator. One shouldn't call `ClearContainer` on a container that is an item. Adjusted `SelectingItemsControlTests` because selection is actually maintained on move with containers hold their own `IsSelected` state. Fixes #11128 --- .../Presenters/PanelContainerGenerator.cs | 5 +- .../Primitives/SelectingItemsControlTests.cs | 49 ++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/PanelContainerGenerator.cs b/src/Avalonia.Controls/Presenters/PanelContainerGenerator.cs index 796ee8433a..5a6f9fc4f9 100644 --- a/src/Avalonia.Controls/Presenters/PanelContainerGenerator.cs +++ b/src/Avalonia.Controls/Presenters/PanelContainerGenerator.cs @@ -67,9 +67,12 @@ namespace Avalonia.Controls.Presenters for (var i = 0; i < count; ++i) { var c = children[index + i]; + if (!c.IsSet(ItemIsOwnContainerProperty)) + { itemsControl.RemoveLogicalChild(children[i + index]); - generator.ClearItemContainer(c); + generator.ClearItemContainer(c); + } } children.RemoveRange(index, count); diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs index db6460e8aa..dfdcd09bf9 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs @@ -676,12 +676,8 @@ namespace Avalonia.Controls.UnitTests.Primitives [Fact] public void Moving_Selected_Item_Should_Clear_Selection() { - var items = new AvaloniaList - { - new Item(), - new Item(), - }; - + using var app = Start(); + var items = new ObservableCollection { "foo", "bar" }; var target = new SelectingItemsControl { ItemsSource = items, @@ -706,7 +702,46 @@ namespace Avalonia.Controls.UnitTests.Primitives Assert.NotNull(receivedArgs); Assert.Empty(receivedArgs.AddedItems); Assert.Equal(new[] { removed }, receivedArgs.RemovedItems); - Assert.All(items, x => Assert.False(x.IsSelected)); + } + + [Fact] + public void Moving_Selected_Container_Should_Not_Clear_Selection() + { + var items = new AvaloniaList + { + new Item(), + new Item(), + }; + + var target = new SelectingItemsControl + { + ItemsSource = items, + Template = Template(), + }; + + Prepare(target); + target.SelectedIndex = 1; + + Assert.Equal(items[1], target.SelectedItem); + Assert.Equal(1, target.SelectedIndex); + + var receivedArgs = new List(); + + target.SelectionChanged += (_, args) => receivedArgs.Add(args); + + var moved = items[1]; + items.Move(1, 0); + + // Because the moved container is still marked as selected on the insert part of the + // move, it will remain selected. + Assert.Same(moved, target.SelectedItem); + Assert.Equal(0, target.SelectedIndex); + Assert.NotNull(receivedArgs); + Assert.Equal(2, receivedArgs.Count); + Assert.Equal(new[] { moved }, receivedArgs[0].RemovedItems); + Assert.Equal(new[] { moved }, receivedArgs[1].AddedItems); + Assert.True(items[0].IsSelected); + Assert.False(items[1].IsSelected); } [Fact] From 2c9f286db066acfa44e7d3f938f5026a2e2ded09 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 26 Apr 2023 14:27:48 +0200 Subject: [PATCH 47/80] Added failing tests for #11119. --- .../CarouselTests.cs | 65 +++++++++++++++++++ .../SelectingItemsControlTests_Multiple.cs | 52 ++++++++++++++- 2 files changed, 116 insertions(+), 1 deletion(-) diff --git a/tests/Avalonia.Controls.UnitTests/CarouselTests.cs b/tests/Avalonia.Controls.UnitTests/CarouselTests.cs index 6624d13165..2a35787f3b 100644 --- a/tests/Avalonia.Controls.UnitTests/CarouselTests.cs +++ b/tests/Avalonia.Controls.UnitTests/CarouselTests.cs @@ -261,6 +261,71 @@ namespace Avalonia.Controls.UnitTests } } + [Fact] + public void Can_Move_Forward_Back_Forward() + { + using var app = Start(); + var items = new[] { "foo", "bar" }; + var target = new Carousel + { + Template = CarouselTemplate(), + ItemsSource = items, + }; + + Prepare(target); + + target.SelectedIndex = 1; + Layout(target); + + Assert.Equal(1, target.SelectedIndex); + + target.SelectedIndex = 0; + Layout(target); + + Assert.Equal(0, target.SelectedIndex); + + target.SelectedIndex = 1; + Layout(target); + + Assert.Equal(1, target.SelectedIndex); + } + + [Fact] + public void Can_Move_Forward_Back_Forward_With_Control_Items() + { + // Issue #11119 + using var app = Start(); + var items = new[] { new Canvas(), new Canvas() }; + var target = new Carousel + { + Template = CarouselTemplate(), + ItemsSource = items, + }; + + Prepare(target); + + target.SelectedIndex = 1; + Layout(target); + + Assert.Equal(1, target.SelectedIndex); + + target.SelectedIndex = 0; + Layout(target); + + Assert.Equal(0, target.SelectedIndex); + + target.SelectedIndex = 1; + target.PropertyChanged += (s, e) => + { + if (e.Property == Carousel.SelectedIndexProperty) + { + } + }; + Layout(target); + + Assert.Equal(1, target.SelectedIndex); + } + private static IDisposable Start() => UnitTestApplication.Start(TestServices.MockPlatformRenderInterface); private static void Prepare(Carousel target) diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs index 0817979e33..928c0c94ef 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs @@ -1024,6 +1024,56 @@ namespace Avalonia.Controls.UnitTests.Primitives Assert.Equal(new[] { 15 }, SelectedContainers(target)); } + [Fact] + public void Can_Change_Selection_For_Containers_Outside_Of_Viewport() + { + // Issue #11119 + using var app = Start(); + var items = Enumerable.Range(0, 100).Select(x => new TestContainer + { + Content = $"Item {x}", + Height = 100, + }).ToList(); + + // Create a SelectingItemsControl with a virtualizing stack panel. + var target = CreateTarget(itemsSource: items, virtualizing: true); + target.AutoScrollToSelectedItem = false; + + var panel = Assert.IsType(target.ItemsPanelRoot); + var scroll = panel.FindAncestorOfType()!; + + // Select item 1. + target.SelectedIndex = 1; + + // Scroll item 1 and 2 out of view. + scroll.Offset = new(0, 1000); + Layout(target); + + Assert.Equal(10, panel.FirstRealizedIndex); + Assert.Equal(19, panel.LastRealizedIndex); + + // Select item 2 now that items 1 and 2 are both unrealized. + target.SelectedIndex = 2; + + // The selection should be updated. + Assert.Empty(SelectedContainers(target)); + Assert.Equal(2, target.SelectedIndex); + Assert.Same(items[2], target.SelectedItem); + Assert.Equal(new[] { 2 }, target.Selection.SelectedIndexes); + Assert.Equal(new[] { items[2] }, target.Selection.SelectedItems); + + // Scroll selected item back into view. + scroll.Offset = new(0, 0); + Layout(target); + + // The selection should be preserved. + Assert.Equal(new[] { 2 }, SelectedContainers(target)); + Assert.Equal(2, target.SelectedIndex); + Assert.Same(items[2], target.SelectedItem); + Assert.Equal(new[] { 2 }, target.Selection.SelectedIndexes); + Assert.Equal(new[] { items[2] }, target.Selection.SelectedItems); + } + [Fact] public void Selection_State_Change_On_Unrealized_Item_Is_Respected_With_IsSelected_Binding() { @@ -1197,7 +1247,7 @@ namespace Avalonia.Controls.UnitTests.Primitives { Setters = { - new Setter(TreeView.TemplateProperty, CreateTestContainerTemplate()), + new Setter(TestContainer.TemplateProperty, CreateTestContainerTemplate()), }, }; } From 8a354d8cb9251ff666d226000af1e5ae6d34cfd0 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 26 Apr 2023 16:54:23 +0200 Subject: [PATCH 48/80] Only prepare items that are containers once. When an `ItemsControl` returns true for `IsItemItsOwnContainer`, `ItemContainerPrepared` should only be called once the first time the container is prepared. Requires that `ContainerFromIndex` returns `ItemIsOwnContainer` items that have previously been prepared in order for `SelectingItemsControl` to update their selection correctly when outside the realized viewport. Fixes #11119 --- .../Generators/ItemContainerGenerator.cs | 28 ++++++++++++++++--- .../VirtualizingCarouselPanel.cs | 9 ++++-- src/Avalonia.Controls/VirtualizingPanel.cs | 5 ++++ .../VirtualizingStackPanel.cs | 14 ++++++++-- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs b/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs index 57ed67b508..f2b105c901 100644 --- a/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs +++ b/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs @@ -7,8 +7,8 @@ namespace Avalonia.Controls.Generators /// /// /// When creating a container for an item from a , the following - /// method order should be followed: - /// + /// process should be followed: + /// /// - should first be called if the item is /// derived from the class. If this method returns true then the /// item itself should be used as the container. @@ -19,9 +19,29 @@ namespace Avalonia.Controls.Generators /// - The container should then be added to the panel using /// /// - Finally, should be called. - /// - When the item is ready to be recycled, should - /// be called if returned false. /// + /// NOTE: If in the first step above returns true + /// then the above steps should be carried out a single time; the first time the item is + /// displayed. Otherwise the steps should be carried out each time a new container is realized + /// for an item. + /// + /// When unrealizing a container, the following process should be followed: + /// + /// - If for the item returned true then the item + /// cannot be unrealized or recycled. + /// - Otherwise, should be called for the container + /// - If recycling is supported then the container should be added to a recycle pool. + /// - It is assumed that recyclable containers will not be removed from the panel but instead + /// hidden from view using e.g. `container.IsVisible = false`. + /// + /// When recycling an unrealized container, the following process should be followed: + /// + /// - An element should be taken from the recycle pool. + /// - The container should be made visible. + /// - method should be called for the + /// container. + /// - should be called. + /// /// NOTE: Although this class is similar to that found in WPF/UWP, in Avalonia this class only /// concerns itself with generating and clearing item containers; it does not maintain a /// record of the currently realized containers, that responsibility is delegated to the diff --git a/src/Avalonia.Controls/VirtualizingCarouselPanel.cs b/src/Avalonia.Controls/VirtualizingCarouselPanel.cs index da0ff1eb69..28d6a83309 100644 --- a/src/Avalonia.Controls/VirtualizingCarouselPanel.cs +++ b/src/Avalonia.Controls/VirtualizingCarouselPanel.cs @@ -168,7 +168,13 @@ namespace Avalonia.Controls protected internal override Control? ContainerFromIndex(int index) { - return index == _realizedIndex ? _realized : null; + if (index < 0 || index >= Items.Count) + return null; + if (index == _realizedIndex) + return _realized; + if (Items[index] is Control c && c.GetValue(ItemIsOwnContainerProperty)) + return c; + return null; } protected internal override IEnumerable? GetRealizedContainers() @@ -264,7 +270,6 @@ namespace Avalonia.Controls if (controlItem.IsSet(ItemIsOwnContainerProperty)) { controlItem.IsVisible = true; - generator.ItemContainerPrepared(controlItem, item, index); return controlItem; } else if (generator.IsItemItsOwnContainer(controlItem)) diff --git a/src/Avalonia.Controls/VirtualizingPanel.cs b/src/Avalonia.Controls/VirtualizingPanel.cs index a95d4f1ffa..ed92f30454 100644 --- a/src/Avalonia.Controls/VirtualizingPanel.cs +++ b/src/Avalonia.Controls/VirtualizingPanel.cs @@ -76,6 +76,11 @@ namespace Avalonia.Controls /// The container for the item at the specified index within the item collection, if the /// item is realized; otherwise, null. /// + /// + /// Note for implementors: if the item at the the specified index is an ItemIsOwnContainer + /// item that has previously been realized, then the item should be returned even if it + /// currently falls outside the realized viewport. + /// protected internal abstract Control? ContainerFromIndex(int index); /// diff --git a/src/Avalonia.Controls/VirtualizingStackPanel.cs b/src/Avalonia.Controls/VirtualizingStackPanel.cs index 77268c7831..67ec238ceb 100644 --- a/src/Avalonia.Controls/VirtualizingStackPanel.cs +++ b/src/Avalonia.Controls/VirtualizingStackPanel.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Linq; -using System.Reflection; using Avalonia.Controls.Primitives; using Avalonia.Controls.Utils; using Avalonia.Input; @@ -326,7 +325,17 @@ namespace Avalonia.Controls return _realizedElements?.Elements.Where(x => x is not null)!; } - protected internal override Control? ContainerFromIndex(int index) => _realizedElements?.GetElement(index); + protected internal override Control? ContainerFromIndex(int index) + { + if (index < 0 || index >= Items.Count) + return null; + if (_realizedElements?.GetElement(index) is { } realized) + return realized; + if (Items[index] is Control c && c.GetValue(ItemIsOwnContainerProperty)) + return c; + return null; + } + protected internal override int IndexFromContainer(Control container) => _realizedElements?.GetIndex(container) ?? -1; protected internal override Control? ScrollIntoView(int index) @@ -578,7 +587,6 @@ namespace Avalonia.Controls if (controlItem.IsSet(ItemIsOwnContainerProperty)) { controlItem.IsVisible = true; - generator.ItemContainerPrepared(controlItem, item, index); return controlItem; } else if (generator.IsItemItsOwnContainer(controlItem)) From 1bdb067ab9e422ba89aea86871c0cf4304ff8931 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 27 Apr 2023 16:42:59 +0600 Subject: [PATCH 49/80] external consumers --- build/ExternalConsumers.props | 32 ++++++++++++++++++++++++++++++++ src/Directory.Build.props | 1 + 2 files changed, 33 insertions(+) create mode 100644 build/ExternalConsumers.props diff --git a/build/ExternalConsumers.props b/build/ExternalConsumers.props new file mode 100644 index 0000000000..d79e951330 --- /dev/null +++ b/build/ExternalConsumers.props @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 55a1014188..45cd4a932b 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -3,6 +3,7 @@ + Shared\_ModuleInitializer.cs From 271cb55b85c09903c49727c43596bcc4d643dd0e Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Thu, 27 Apr 2023 17:48:19 +0600 Subject: [PATCH 50/80] Remove ModuleInitializer duplicates --- src/Avalonia.Base/Avalonia.Base.csproj | 1 + src/Directory.Build.props | 6 ------ src/Windows/Avalonia.Win32/Avalonia.Win32.csproj | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Avalonia.Base/Avalonia.Base.csproj b/src/Avalonia.Base/Avalonia.Base.csproj index 639c27bf03..eafff3b780 100644 --- a/src/Avalonia.Base/Avalonia.Base.csproj +++ b/src/Avalonia.Base/Avalonia.Base.csproj @@ -22,6 +22,7 @@ + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 45cd4a932b..51f6cc92e9 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -4,10 +4,4 @@ - - - Shared\_ModuleInitializer.cs - false - - diff --git a/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj b/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj index 2c5f3e2ed1..61f5996a94 100644 --- a/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj +++ b/src/Windows/Avalonia.Win32/Avalonia.Win32.csproj @@ -20,7 +20,6 @@ - From 5391361d4501ddde8eebeb0525fcf82e4b616754 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 27 Apr 2023 22:39:50 +0200 Subject: [PATCH 51/80] Failing test for selection w/ virtualization. --- .../SelectingItemsControlTests_Multiple.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs index 928c0c94ef..daebc1e709 100644 --- a/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs +++ b/tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs @@ -1074,6 +1074,40 @@ namespace Avalonia.Controls.UnitTests.Primitives Assert.Equal(new[] { items[2] }, target.Selection.SelectedItems); } + [Fact] + public void Selection_Is_Not_Cleared_On_Recycling_Containers() + { + using var app = Start(); + var items = Enumerable.Range(0, 100).Select(x => new ItemViewModel($"Item {x}", false)).ToList(); + + // Create a SelectingItemsControl that creates containers that raise IsSelectedChanged, + // with a virtualizing stack panel. + var target = CreateTarget( + itemsSource: items, + virtualizing: true); + target.AutoScrollToSelectedItem = false; + + var panel = Assert.IsType(target.ItemsPanelRoot); + var scroll = panel.FindAncestorOfType()!; + + // Select item 1. + target.SelectedIndex = 1; + + // Scroll item 1 out of view. + scroll.Offset = new(0, 1000); + Layout(target); + + Assert.Equal(10, panel.FirstRealizedIndex); + Assert.Equal(19, panel.LastRealizedIndex); + + // The selection should be preserved. + Assert.Empty(SelectedContainers(target)); + Assert.Equal(1, target.SelectedIndex); + Assert.Same(items[1], target.SelectedItem); + Assert.Equal(new[] { 1 }, target.Selection.SelectedIndexes); + Assert.Equal(new[] { items[1] }, target.Selection.SelectedItems); + } + [Fact] public void Selection_State_Change_On_Unrealized_Item_Is_Respected_With_IsSelected_Binding() { @@ -1248,6 +1282,7 @@ namespace Avalonia.Controls.UnitTests.Primitives Setters = { new Setter(TestContainer.TemplateProperty, CreateTestContainerTemplate()), + new Setter(TestContainer.HeightProperty, 100.0), }, }; } From 8a5a5c8d441d10699f5b696524064d0fddae3716 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 27 Apr 2023 22:51:43 +0200 Subject: [PATCH 52/80] Remove element from list before recycling. Remove the element from the realized element list before recycling it, so that `IndexFromContainer` and `ContainerFromIndex` report the container as not found during `ClearItemContainer`. Fixes selection being reset when a container is unrealized. --- .../Utils/RealizedStackElements.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Avalonia.Controls/Utils/RealizedStackElements.cs b/src/Avalonia.Controls/Utils/RealizedStackElements.cs index 8dbfb2c957..11bbaa11c4 100644 --- a/src/Avalonia.Controls/Utils/RealizedStackElements.cs +++ b/src/Avalonia.Controls/Utils/RealizedStackElements.cs @@ -353,7 +353,10 @@ namespace Avalonia.Controls.Utils for (var i = start; i < end; ++i) { if (_elements[i] is Control element) + { + _elements[i] = null; recycleElement(element); + } } _elements.RemoveRange(start, end - start); @@ -389,10 +392,13 @@ namespace Avalonia.Controls.Utils if (_elements is null || _elements.Count == 0) return; - foreach (var e in _elements) + for (var i = 0; i < _elements.Count; i++) { - if (e is not null) + if (_elements[i] is Control e) + { + _elements[i] = null; recycleElement(e); + } } _startU = _firstIndex = 0; @@ -422,7 +428,10 @@ namespace Avalonia.Controls.Utils for (var i = 0; i < endIndex; ++i) { if (_elements[i] is Control e) + { + _elements[i] = null; recycleElement(e, i + FirstIndex); + } } _elements.RemoveRange(0, endIndex); @@ -453,7 +462,10 @@ namespace Avalonia.Controls.Utils for (var i = startIndex; i < count; ++i) { if (_elements[i] is Control e) + { + _elements[i] = null; recycleElement(e, i + FirstIndex); + } } _elements.RemoveRange(startIndex, _elements.Count - startIndex); @@ -470,13 +482,13 @@ namespace Avalonia.Controls.Utils if (_elements is null || _elements.Count == 0) return; - var i = FirstIndex; - - foreach (var e in _elements) + for (var i = 0; i < _elements.Count; i++) { - if (e is not null) - recycleElement(e, i); - ++i; + if (_elements[i] is Control e) + { + _elements[i] = null; + recycleElement(e, i + FirstIndex); + } } _startU = _firstIndex = 0; From 3d693beffa5d548199b555febf3af1c6e3128bde Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 27 Apr 2023 22:57:17 +0200 Subject: [PATCH 53/80] Clarify `ClearItemContainer` docs. And change usages of "should" to "must" as it's not optional. --- .../Generators/ItemContainerGenerator.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs b/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs index f2b105c901..b2c138599e 100644 --- a/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs +++ b/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs @@ -85,7 +85,7 @@ namespace Avalonia.Controls.Generators /// The index of the item to display. /// /// If is true for an item, then this method - /// only needs to be called a single time, otherwise this method should be called after the + /// must only be called a single time, otherwise this method must be called after the /// container is created, and each subsequent time the container is recycled to display a /// new item. /// @@ -100,10 +100,11 @@ namespace Avalonia.Controls.Generators /// The item being displayed. /// The index of the item being displayed. /// - /// This method should be called when a container has been fully prepared and added + /// This method must be called when a container has been fully prepared and added /// to the logical and visual trees, but may be called before a layout pass has completed. - /// It should be called regardless of the result of - /// . + /// It must be called regardless of the result of + /// but if that method returned true then + /// must be called only a single time. /// public void ItemContainerPrepared(Control container, object? item, int index) => _owner.ItemContainerPrepared(container, item, index); @@ -122,6 +123,12 @@ namespace Avalonia.Controls.Generators /// Undoes the effects of the method. /// /// The container control. + /// + /// This method must be called when a container is unrealized. The container must have + /// already have been removed from the virtualizing panel's list of realized containers before + /// this method is called. This method must not be called if + /// returned true for the item. + /// public void ClearItemContainer(Control container) => _owner.ClearItemContainer(container); [Obsolete("Use ItemsControl.ContainerFromIndex")] From 92b5a46b27bed1db89bc13f23aaa45ef015c1d70 Mon Sep 17 00:00:00 2001 From: Sergey Mikolaitis Date: Fri, 28 Apr 2023 01:45:22 +0300 Subject: [PATCH 54/80] [Input] fix also timestamp on C# side --- src/Avalonia.Native/WindowImplBase.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Native/WindowImplBase.cs b/src/Avalonia.Native/WindowImplBase.cs index 26c3da9d50..b802b1db71 100644 --- a/src/Avalonia.Native/WindowImplBase.cs +++ b/src/Avalonia.Native/WindowImplBase.cs @@ -220,17 +220,17 @@ namespace Avalonia.Native _parent.PositionChanged?.Invoke(position.ToAvaloniaPixelPoint()); } - void IAvnWindowBaseEvents.RawMouseEvent(AvnRawMouseEventType type, uint timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta) + void IAvnWindowBaseEvents.RawMouseEvent(AvnRawMouseEventType type, ulong timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta) { _parent.RawMouseEvent(type, timeStamp, modifiers, point, delta); } - int IAvnWindowBaseEvents.RawKeyEvent(AvnRawKeyEventType type, uint timeStamp, AvnInputModifiers modifiers, uint key) + int IAvnWindowBaseEvents.RawKeyEvent(AvnRawKeyEventType type, ulong timeStamp, AvnInputModifiers modifiers, uint key) { return _parent.RawKeyEvent(type, timeStamp, modifiers, key).AsComBool(); } - int IAvnWindowBaseEvents.RawTextInputEvent(uint timeStamp, string text) + int IAvnWindowBaseEvents.RawTextInputEvent(ulong timeStamp, string text) { return _parent.RawTextInputEvent(timeStamp, text).AsComBool(); } @@ -286,7 +286,7 @@ namespace Avalonia.Native _native?.Activate(); } - public bool RawTextInputEvent(uint timeStamp, string text) + public bool RawTextInputEvent(ulong timeStamp, string text) { if (_inputRoot is null) return false; @@ -300,7 +300,7 @@ namespace Avalonia.Native return args.Handled; } - public bool RawKeyEvent(AvnRawKeyEventType type, uint timeStamp, AvnInputModifiers modifiers, uint key) + public bool RawKeyEvent(AvnRawKeyEventType type, ulong timeStamp, AvnInputModifiers modifiers, uint key) { if (_inputRoot is null) return false; @@ -319,7 +319,7 @@ namespace Avalonia.Native return false; } - public void RawMouseEvent(AvnRawMouseEventType type, uint timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta) + public void RawMouseEvent(AvnRawMouseEventType type, ulong timeStamp, AvnInputModifiers modifiers, AvnPoint point, AvnVector delta) { if (_inputRoot is null) return; From 110b536738e5ca16776eb7b9d8bddd4822a42c77 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Fri, 28 Apr 2023 11:55:37 +0200 Subject: [PATCH 55/80] fix(Animation): fix Issue #11156 System.InvalidOperationException: Call from invalid thread --- src/Avalonia.Base/Animation/Animation.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Base/Animation/Animation.cs b/src/Avalonia.Base/Animation/Animation.cs index d62acc0d52..dd99c40cd3 100644 --- a/src/Avalonia.Base/Animation/Animation.cs +++ b/src/Avalonia.Base/Animation/Animation.cs @@ -200,7 +200,7 @@ namespace Avalonia.Animation /// /// The animation setter. /// The property animator value. - public static void SetAnimator(IAnimationSetter setter, + public static void SetAnimator(IAnimationSetter setter, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicMethods)] Type value) { @@ -319,7 +319,7 @@ namespace Avalonia.Animation if (animators.Count == 1) { var subscription = animators[0].Apply(this, control, clock, match, onComplete); - + if (subscription is not null) { subscriptions.Add(subscription); @@ -348,9 +348,11 @@ namespace Avalonia.Animation if (onComplete != null) { - Task.WhenAll(completionTasks!).ContinueWith( - (_, state) => ((Action)state!).Invoke(), - onComplete); + Task.WhenAll(completionTasks!) + .ContinueWith((_, state) => ((Action)state!).Invoke() + , onComplete + , TaskScheduler.FromCurrentSynchronizationContext() + ); } } return new CompositeDisposable(subscriptions); From c4a5567090357c49d0b69634406d6cb3195cd625 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 28 Apr 2023 12:32:20 +0200 Subject: [PATCH 56/80] Added failing test for #11161. --- .../Layout/LayoutManagerTests.cs | 33 +++++++++++++++++++ .../Layout/LayoutTestControl.cs | 32 ++++++++++++++---- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs b/tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs index 09f78c5a6c..45a6efdd4a 100644 --- a/tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs +++ b/tests/Avalonia.Base.UnitTests/Layout/LayoutManagerTests.cs @@ -514,5 +514,38 @@ namespace Avalonia.Base.UnitTests.Layout Assert.True(parent.IsMeasureValid); Assert.True(parent.IsArrangeValid); } + + [Fact] + public void Grandparent_Can_Invalidate_Root_Measure_During_Arrange() + { + // Issue #11161. + var child = new LayoutTestControl(); + var parent = new LayoutTestControl { Child = child }; + var grandparent = new LayoutTestControl { Child = parent }; + var root = new LayoutTestRoot { Child = grandparent }; + + root.LayoutManager.ExecuteInitialLayoutPass(); + + grandparent.DoArrangeOverride = (_, s) => + { + root.InvalidateMeasure(); + return s; + }; + grandparent.CallBaseArrange = true; + + child.InvalidateMeasure(); + grandparent.InvalidateMeasure(); + + root.LayoutManager.ExecuteLayoutPass(); + + Assert.True(child.IsMeasureValid); + Assert.True(child.IsArrangeValid); + Assert.True(parent.IsMeasureValid); + Assert.True(parent.IsArrangeValid); + Assert.True(grandparent.IsMeasureValid); + Assert.True(grandparent.IsArrangeValid); + Assert.True(root.IsMeasureValid); + Assert.True(root.IsArrangeValid); + } } } diff --git a/tests/Avalonia.Base.UnitTests/Layout/LayoutTestControl.cs b/tests/Avalonia.Base.UnitTests/Layout/LayoutTestControl.cs index 62de81006e..d85c7ed9bc 100644 --- a/tests/Avalonia.Base.UnitTests/Layout/LayoutTestControl.cs +++ b/tests/Avalonia.Base.UnitTests/Layout/LayoutTestControl.cs @@ -10,21 +10,41 @@ namespace Avalonia.Base.UnitTests.Layout public bool Arranged { get; set; } public Func DoMeasureOverride { get; set; } public Func DoArrangeOverride { get; set; } + public bool CallBaseMeasure { get; set; } + public bool CallBaseArrange { get; set; } protected override Size MeasureOverride(Size availableSize) { Measured = true; - return DoMeasureOverride != null ? - DoMeasureOverride(this, availableSize) : - base.MeasureOverride(availableSize); + + if (DoMeasureOverride is not null) + { + var overrideResult = DoMeasureOverride(this, availableSize); + return CallBaseMeasure ? + base.MeasureOverride(overrideResult) : + overrideResult; + } + else + { + return base.MeasureOverride(availableSize); + } } protected override Size ArrangeOverride(Size finalSize) { Arranged = true; - return DoArrangeOverride != null ? - DoArrangeOverride(this, finalSize) : - base.ArrangeOverride(finalSize); + + if (DoArrangeOverride is not null) + { + var overrideResult = DoArrangeOverride(this, finalSize); + return CallBaseArrange ? + base.ArrangeOverride(overrideResult) : + overrideResult; + } + else + { + return base.ArrangeOverride(finalSize); + } } } } From a03b73a7347fe442e141ead2662328cf686f3eee Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 28 Apr 2023 13:02:37 +0200 Subject: [PATCH 57/80] Always add control in measure queue to arrange queue. And also removed the checks for `IsAttachedToVisualTree`: that's going to be checked in `Arrange` and `Measure`. Fixes #11161 --- src/Avalonia.Base/Layout/LayoutManager.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Base/Layout/LayoutManager.cs b/src/Avalonia.Base/Layout/LayoutManager.cs index 747ee1c082..f47738f2e4 100644 --- a/src/Avalonia.Base/Layout/LayoutManager.cs +++ b/src/Avalonia.Base/Layout/LayoutManager.cs @@ -249,10 +249,12 @@ namespace Avalonia.Layout { var control = _toMeasure.Dequeue(); - if (!control.IsMeasureValid && control.IsAttachedToVisualTree) + if (!control.IsMeasureValid) { Measure(control); } + + _toArrange.Enqueue(control); } } @@ -262,7 +264,7 @@ namespace Avalonia.Layout { var control = _toArrange.Dequeue(); - if (!control.IsArrangeValid && control.IsAttachedToVisualTree) + if (!control.IsArrangeValid) { Arrange(control); } @@ -297,8 +299,6 @@ namespace Avalonia.Layout { control.Measure(control.PreviousMeasure.Value); } - - _toArrange.Enqueue(control); } return true; From 9a062901425a5166c23a5334df649d4d50412903 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Fri, 28 Apr 2023 17:51:41 +0200 Subject: [PATCH 58/80] Correctly remove ContentPresenter's content from its parent host When the content is updated while being detached from the visual tree. --- src/Avalonia.Controls/Presenters/ContentPresenter.cs | 9 ++++++--- tests/Avalonia.Controls.UnitTests/ContentControlTests.cs | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/ContentPresenter.cs b/src/Avalonia.Controls/Presenters/ContentPresenter.cs index 329a0fa6ab..736c338c10 100644 --- a/src/Avalonia.Controls/Presenters/ContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ContentPresenter.cs @@ -1,5 +1,5 @@ using System; - +using Avalonia.Collections; using Avalonia.Controls.Documents; using Avalonia.Controls.Metadata; using Avalonia.Controls.Primitives; @@ -442,7 +442,7 @@ namespace Avalonia.Controls.Presenters var contentTemplate = ContentTemplate; var oldChild = Child; var newChild = CreateChild(content, oldChild, contentTemplate); - var logicalChildren = Host?.LogicalChildren ?? LogicalChildren; + var logicalChildren = GetEffectiveLogicalChildren(); // Remove the old child if we're not recycling it. if (newChild != oldChild) @@ -488,6 +488,9 @@ namespace Avalonia.Controls.Presenters } + private IAvaloniaList GetEffectiveLogicalChildren() + => Host?.LogicalChildren ?? LogicalChildren; + /// protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) { @@ -692,7 +695,7 @@ namespace Avalonia.Controls.Presenters else if (Child != null) { VisualChildren.Remove(Child); - LogicalChildren.Remove(Child); + GetEffectiveLogicalChildren().Remove(Child); ((ISetInheritanceParent)Child).SetParent(Child.Parent); Child = null; _recyclingDataTemplate = null; diff --git a/tests/Avalonia.Controls.UnitTests/ContentControlTests.cs b/tests/Avalonia.Controls.UnitTests/ContentControlTests.cs index bece711426..d5e4693666 100644 --- a/tests/Avalonia.Controls.UnitTests/ContentControlTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ContentControlTests.cs @@ -359,16 +359,21 @@ namespace Avalonia.Controls.UnitTests target.Presenter.ApplyTemplate(); Assert.Equal(target, target.Presenter.Child.GetLogicalParent()); + Assert.Equal(new[] { target.Presenter.Child }, target.LogicalChildren); root.Child = null; Assert.Null(target.Template); target.Content = null; + + Assert.Empty(target.LogicalChildren); + root.Child = target; target.Content = "Bar"; Assert.Equal(target, target.Presenter.Child.GetLogicalParent()); + Assert.Equal(new[] { target.Presenter.Child }, target.LogicalChildren); } private static FuncControlTemplate GetTemplate() From b9fd35051f9352148804e2f676623a2e1f30893d Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Thu, 27 Apr 2023 12:41:39 +0000 Subject: [PATCH 59/80] store IRuntimePlatform in DeferredParentServiceProvider --- .../XamlIl/Runtime/XamlIlRuntimeHelpers.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs index 0cc7cc5468..6f5e822079 100644 --- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs +++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs @@ -50,6 +50,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime private readonly IServiceProvider? _parentProvider; private readonly List? _parentResourceNodes; private readonly INameScope _nameScope; + private readonly IRuntimePlatform? _runtimePlatform; public DeferredParentServiceProvider(IServiceProvider? parentProvider, List? parentResourceNodes, object rootObject, INameScope nameScope) @@ -58,6 +59,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime _parentResourceNodes = parentResourceNodes; _nameScope = nameScope; RootObject = rootObject; + _runtimePlatform = AvaloniaLocator.Current.GetService(); } public IEnumerable Parents => GetParents(); @@ -80,6 +82,8 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime return this; if (serviceType == typeof(IAvaloniaXamlIlControlTemplateProvider)) return this; + if (serviceType == typeof(IRuntimePlatform)) + return _runtimePlatform; return _parentProvider?.GetService(serviceType); } From 75cbab78ad4f6b5f1fd22769bfdc1177594f26bb Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Sat, 29 Apr 2023 08:00:14 +0000 Subject: [PATCH 60/80] only store runtime platform when requested --- .../XamlIl/Runtime/XamlIlRuntimeHelpers.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs index 6f5e822079..f8eab5b654 100644 --- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs +++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/Runtime/XamlIlRuntimeHelpers.cs @@ -50,7 +50,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime private readonly IServiceProvider? _parentProvider; private readonly List? _parentResourceNodes; private readonly INameScope _nameScope; - private readonly IRuntimePlatform? _runtimePlatform; + private IRuntimePlatform? _runtimePlatform; public DeferredParentServiceProvider(IServiceProvider? parentProvider, List? parentResourceNodes, object rootObject, INameScope nameScope) @@ -59,7 +59,6 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime _parentResourceNodes = parentResourceNodes; _nameScope = nameScope; RootObject = rootObject; - _runtimePlatform = AvaloniaLocator.Current.GetService(); } public IEnumerable Parents => GetParents(); @@ -83,7 +82,11 @@ namespace Avalonia.Markup.Xaml.XamlIl.Runtime if (serviceType == typeof(IAvaloniaXamlIlControlTemplateProvider)) return this; if (serviceType == typeof(IRuntimePlatform)) + { + if(_runtimePlatform == null) + _runtimePlatform = AvaloniaLocator.Current.GetService(); return _runtimePlatform; + } return _parentProvider?.GetService(serviceType); } From bc79b388b57703a20b09f7c8de38b2d19b6aaab0 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 29 Apr 2023 22:06:45 -0400 Subject: [PATCH 61/80] Use ImmediateDrawingContext in the ICustomDrawOperation interface --- samples/RenderDemo/Pages/CustomSkiaPage.cs | 4 ++-- .../Media/PlatformDrawingContext.cs | 16 ++++++++++++++-- .../Rendering/SceneGraph/CustomDrawOperation.cs | 14 ++++++++++++-- .../Avalonia.Browser/WebEmbeddableControlRoot.cs | 2 +- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/samples/RenderDemo/Pages/CustomSkiaPage.cs b/samples/RenderDemo/Pages/CustomSkiaPage.cs index 4a3e20ff5b..2d64ba8f7b 100644 --- a/samples/RenderDemo/Pages/CustomSkiaPage.cs +++ b/samples/RenderDemo/Pages/CustomSkiaPage.cs @@ -44,9 +44,9 @@ namespace RenderDemo.Pages public bool HitTest(Point p) => false; public bool Equals(ICustomDrawOperation other) => false; static Stopwatch St = Stopwatch.StartNew(); - public void Render(IDrawingContextImpl context) + public void Render(ImmediateDrawingContext context) { - var leaseFeature = context.GetFeature(); + var leaseFeature = context.TryGetFeature(); if (leaseFeature == null) context.DrawGlyphRun(Brushes.Black, _noSkia.PlatformImpl); else diff --git a/src/Avalonia.Base/Media/PlatformDrawingContext.cs b/src/Avalonia.Base/Media/PlatformDrawingContext.cs index eb8a93722c..4b683c6acb 100644 --- a/src/Avalonia.Base/Media/PlatformDrawingContext.cs +++ b/src/Avalonia.Base/Media/PlatformDrawingContext.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Avalonia.Logging; using Avalonia.Media.Imaging; using Avalonia.Media.Immutable; using Avalonia.Platform; @@ -41,8 +42,19 @@ internal sealed class PlatformDrawingContext : DrawingContext, IDrawingContextWi BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default) => _impl.DrawBitmap(source, opacity, sourceRect, destRect, bitmapInterpolationMode); - public override void Custom(ICustomDrawOperation custom) => - custom.Render(_impl); + public override void Custom(ICustomDrawOperation custom) + { + using var immediateDrawingContext = new ImmediateDrawingContext(_impl, false); + try + { + custom.Render(immediateDrawingContext); + } + catch (Exception e) + { + Logger.TryGet(LogEventLevel.Error, LogArea.Visual) + ?.Log(custom, $"Exception in {custom.GetType().Name}.{nameof(ICustomDrawOperation.Render)} {{0}}", e); + } + } public override void DrawGlyphRun(IBrush? foreground, GlyphRun glyphRun) { diff --git a/src/Avalonia.Base/Rendering/SceneGraph/CustomDrawOperation.cs b/src/Avalonia.Base/Rendering/SceneGraph/CustomDrawOperation.cs index 8f5ccb4e51..7ce9e6a8af 100644 --- a/src/Avalonia.Base/Rendering/SceneGraph/CustomDrawOperation.cs +++ b/src/Avalonia.Base/Rendering/SceneGraph/CustomDrawOperation.cs @@ -1,4 +1,5 @@ using System; +using Avalonia.Logging; using Avalonia.Media; using Avalonia.Platform; @@ -17,7 +18,16 @@ namespace Avalonia.Rendering.SceneGraph public override void Render(IDrawingContextImpl context) { - Custom.Render(context); + using var immediateDrawingContext = new ImmediateDrawingContext(context, false); + try + { + Custom.Render(immediateDrawingContext); + } + catch (Exception e) + { + Logger.TryGet(LogEventLevel.Error, LogArea.Visual) + ?.Log(Custom, $"Exception in {Custom.GetType().Name}.{nameof(ICustomDrawOperation.Render)} {{0}}", e); + } } public override void Dispose() => Custom.Dispose(); @@ -48,6 +58,6 @@ namespace Avalonia.Rendering.SceneGraph /// Renders the node to a drawing context. /// /// The drawing context. - void Render(IDrawingContextImpl context); + void Render(ImmediateDrawingContext context); } } diff --git a/src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs b/src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs index df1a24fa0f..993414f17f 100644 --- a/src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs +++ b/src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs @@ -37,7 +37,7 @@ namespace Avalonia.Browser return false; } - public void Render(IDrawingContextImpl context) + public void Render(ImmediateDrawingContext context) { _hasRendered = true; _onFirstRender(); From cc0e2302e7a58dd5453dfa2e315179b506abbf37 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 29 Apr 2023 22:07:12 -0400 Subject: [PATCH 62/80] Remove ICustomDrawOperation from the IDrawingContextImpl as it seems useless there now --- src/Avalonia.Base/Media/ImmediateDrawingContext.cs | 1 - src/Avalonia.Base/Platform/IDrawingContextImpl.cs | 7 ------- .../Rendering/Composition/Server/DrawingContextProxy.cs | 5 ----- .../Avalonia.Headless/HeadlessPlatformRenderInterface.cs | 7 +------ src/Skia/Avalonia.Skia/DrawingContextImpl.cs | 9 --------- .../Avalonia.Direct2D1/Media/DrawingContextImpl.cs | 5 +---- 6 files changed, 2 insertions(+), 32 deletions(-) diff --git a/src/Avalonia.Base/Media/ImmediateDrawingContext.cs b/src/Avalonia.Base/Media/ImmediateDrawingContext.cs index 58b153482d..17c4560523 100644 --- a/src/Avalonia.Base/Media/ImmediateDrawingContext.cs +++ b/src/Avalonia.Base/Media/ImmediateDrawingContext.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using Avalonia.Platform; -using Avalonia.Rendering.SceneGraph; using Avalonia.Threading; using Avalonia.Utilities; using Avalonia.Media.Imaging; diff --git a/src/Avalonia.Base/Platform/IDrawingContextImpl.cs b/src/Avalonia.Base/Platform/IDrawingContextImpl.cs index 1359ad6603..ef53024508 100644 --- a/src/Avalonia.Base/Platform/IDrawingContextImpl.cs +++ b/src/Avalonia.Base/Platform/IDrawingContextImpl.cs @@ -1,6 +1,5 @@ using System; using Avalonia.Media; -using Avalonia.Rendering.SceneGraph; using Avalonia.Utilities; using Avalonia.Media.Imaging; using Avalonia.Metadata; @@ -168,12 +167,6 @@ namespace Avalonia.Platform /// void PopBitmapBlendMode(); - /// - /// Adds a custom draw operation - /// - /// Custom draw operation - void Custom(ICustomDrawOperation custom); - /// /// Attempts to get an optional feature from the drawing context implementation /// diff --git a/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs b/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs index 1ec1362a4c..901bdaae0d 100644 --- a/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs +++ b/src/Avalonia.Base/Rendering/Composition/Server/DrawingContextProxy.cs @@ -143,11 +143,6 @@ internal class CompositorDrawingContextProxy : IDrawingContextImpl, _impl.PopBitmapBlendMode(); } - public void Custom(ICustomDrawOperation custom) - { - _impl.Custom(custom); - } - public object? GetFeature(Type t) => _impl.GetFeature(t); diff --git a/src/Headless/Avalonia.Headless/HeadlessPlatformRenderInterface.cs b/src/Headless/Avalonia.Headless/HeadlessPlatformRenderInterface.cs index b23697fd2a..38375045cb 100644 --- a/src/Headless/Avalonia.Headless/HeadlessPlatformRenderInterface.cs +++ b/src/Headless/Avalonia.Headless/HeadlessPlatformRenderInterface.cs @@ -433,12 +433,7 @@ namespace Avalonia.Headless { } - - public void Custom(ICustomDrawOperation custom) - { - - } - + public object? GetFeature(Type t) { return null; diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs index f48d45f961..cea55f4d29 100644 --- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs +++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs @@ -5,12 +5,9 @@ using System.Linq; using System.Threading; using Avalonia.Media; using Avalonia.Platform; -using Avalonia.Rendering; -using Avalonia.Rendering.SceneGraph; using Avalonia.Rendering.Utilities; using Avalonia.Utilities; using Avalonia.Media.Imaging; -using Avalonia.Skia.Helpers; using SkiaSharp; using ISceneBrush = Avalonia.Media.ISceneBrush; @@ -667,12 +664,6 @@ namespace Avalonia.Skia _currentBlendingMode = _blendingModeStack.Pop(); } - public void Custom(ICustomDrawOperation custom) - { - CheckLease(); - custom.Render(this); - } - /// public void PushOpacityMask(IBrush mask, Rect bounds) { diff --git a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs index 318b0fe9ae..be5cef35b5 100644 --- a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs +++ b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Numerics; using Avalonia.Media; using Avalonia.Platform; -using Avalonia.Rendering; -using Avalonia.Rendering.SceneGraph; using Avalonia.Utilities; using Avalonia.Media.Imaging; using SharpDX; @@ -608,8 +606,7 @@ namespace Avalonia.Direct2D1.Media { PopLayer(); } - - public void Custom(ICustomDrawOperation custom) => custom.Render(this); + public object GetFeature(Type t) => null; } } From 810558140f9ca3541b7709f2791add0b6db817e1 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 29 Apr 2023 23:25:05 -0400 Subject: [PATCH 63/80] Introduce static AssetLoader --- src/Avalonia.Base/Platform/AssetLoader.cs | 295 ++---------------- .../Platform/StandardAssetLoader.cs | 256 +++++++++++++++ .../StandardRuntimePlatformServices.cs | 2 +- .../AssetLoaderTests.cs | 23 +- .../Styling/ResourceBenchmarks.cs | 2 +- .../Xaml/StyleIncludeTests.cs | 2 +- tests/Avalonia.RenderTests/TestBase.cs | 2 +- tests/Avalonia.UnitTests/TestServices.cs | 8 +- 8 files changed, 304 insertions(+), 286 deletions(-) create mode 100644 src/Avalonia.Base/Platform/StandardAssetLoader.cs diff --git a/src/Avalonia.Base/Platform/AssetLoader.cs b/src/Avalonia.Base/Platform/AssetLoader.cs index 7df446e854..854610f1c9 100644 --- a/src/Avalonia.Base/Platform/AssetLoader.cs +++ b/src/Avalonia.Base/Platform/AssetLoader.cs @@ -1,281 +1,48 @@ -using System; +using System; using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; using System.IO; -using System.Linq; using System.Reflection; -#if !BUILDTASK -using Avalonia.Platform.Internal; -using Avalonia.Utilities; -#endif -namespace Avalonia.Platform -{ - /// - /// Loads assets compiled into the application binary. - /// - public class AssetLoader +namespace Avalonia.Platform; + #if !BUILDTASK - : IAssetLoader +/// #endif - { +public static class AssetLoader +{ #if !BUILDTASK - private static IAssemblyDescriptorResolver s_assemblyDescriptorResolver = new AssemblyDescriptorResolver(); - - private AssemblyDescriptor? _defaultResmAssembly; - - /// - /// Introduced for tests. - /// - internal static void SetAssemblyDescriptorResolver(IAssemblyDescriptorResolver resolver) => - s_assemblyDescriptorResolver = resolver; - - /// - /// Initializes a new instance of the class. - /// - /// - /// The default assembly from which to load resm: assets for which no assembly is specified. - /// - public AssetLoader(Assembly? assembly = null) - { - if (assembly == null) - assembly = Assembly.GetEntryAssembly(); - if (assembly != null) - _defaultResmAssembly = new AssemblyDescriptor(assembly); - } - - /// - /// Sets the default assembly from which to load assets for which no assembly is specified. - /// - /// The default assembly. - public void SetDefaultAssembly(Assembly assembly) - { - _defaultResmAssembly = new AssemblyDescriptor(assembly); - } - - /// - /// Checks if an asset with the specified URI exists. - /// - /// The URI. - /// - /// A base URI to use if is relative. - /// - /// True if the asset could be found; otherwise false. - public bool Exists(Uri uri, Uri? baseUri = null) - { - return TryGetAsset(uri, baseUri, out _); - } - - /// - /// Opens the asset with the requested URI. - /// - /// The URI. - /// - /// A base URI to use if is relative. - /// - /// A stream containing the asset contents. - /// - /// The asset could not be found. - /// - public Stream Open(Uri uri, Uri? baseUri = null) => OpenAndGetAssembly(uri, baseUri).Item1; - - /// - /// Opens the asset with the requested URI and returns the asset stream and the - /// assembly containing the asset. - /// - /// The URI. - /// - /// A base URI to use if is relative. - /// - /// - /// The stream containing the resource contents together with the assembly. - /// - /// - /// The asset could not be found. - /// - public (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri? baseUri = null) - { - if (TryGetAsset(uri, baseUri, out var assetDescriptor)) - { - return (assetDescriptor.GetStream(), assetDescriptor.Assembly); - } - - throw new FileNotFoundException($"The resource {uri} could not be found."); - } - - public Assembly? GetAssembly(Uri uri, Uri? baseUri) - { - if (!uri.IsAbsoluteUri && baseUri != null) - { - uri = new Uri(baseUri, uri); - } - - if (TryGetAssembly(uri, out var assemblyDescriptor)) - { - return assemblyDescriptor.Assembly; - } - - return null; - } - - /// - /// Gets all assets of a folder and subfolders that match specified uri. - /// - /// The URI. - /// Base URI that is used if is relative. - /// All matching assets as a tuple of the absolute path to the asset and the assembly containing the asset - public IEnumerable GetAssets(Uri uri, Uri? baseUri) - { - if (uri.IsAbsoluteResm()) - { - if (!TryGetAssembly(uri, out var assembly)) - { - assembly = _defaultResmAssembly; - } - - return assembly?.Resources? - .Where(x => x.Key.Contains(uri.GetUnescapeAbsolutePath())) - .Select(x => new Uri($"resm:{x.Key}?assembly={assembly.Name}")) ?? - Enumerable.Empty(); - } - - uri = uri.EnsureAbsolute(baseUri); - - if (uri.IsAvares()) - { - if (!TryGetResAsmAndPath(uri, out var assembly, out var path)) - { - return Enumerable.Empty(); - } + private static IAssetLoader GetAssetLoader() => AvaloniaLocator.Current.GetRequiredService(); - if (assembly?.AvaloniaResources == null) - { - return Enumerable.Empty(); - } + /// + public static void SetDefaultAssembly(Assembly assembly) => GetAssetLoader().SetDefaultAssembly(assembly); - if (path.Length > 0 && path[path.Length - 1] != '/') - { - path += '/'; - } + /// + public static bool Exists(Uri uri, Uri? baseUri = null) => GetAssetLoader().Exists(uri, baseUri); - return assembly.AvaloniaResources - .Where(r => r.Key.StartsWith(path, StringComparison.Ordinal)) - .Select(x => new Uri($"avares://{assembly.Name}{x.Key}")); - } + /// + public static Stream Open(Uri uri, Uri? baseUri = null) => GetAssetLoader().Open(uri, baseUri); - return Enumerable.Empty(); - } + /// + public static (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri? baseUri = null) + => GetAssetLoader().OpenAndGetAssembly(uri, baseUri); - private bool TryGetAsset(Uri uri, Uri? baseUri, [NotNullWhen(true)] out IAssetDescriptor? assetDescriptor) - { - assetDescriptor = null; + /// + public static Assembly? GetAssembly(Uri uri, Uri? baseUri = null) + => GetAssetLoader().GetAssembly(uri, baseUri); - if (uri.IsAbsoluteResm()) - { - if (!TryGetAssembly(uri, out var assembly) && !TryGetAssembly(baseUri, out assembly)) - { - assembly = _defaultResmAssembly; - } - - if (assembly?.Resources != null) - { - var resourceKey = uri.AbsolutePath; - - if (assembly.Resources.TryGetValue(resourceKey, out assetDescriptor)) - { - return true; - } - } - } - - uri = uri.EnsureAbsolute(baseUri); - - if (uri.IsAvares()) - { - if (TryGetResAsmAndPath(uri, out var assembly, out var path)) - { - if (assembly.AvaloniaResources == null) - { - return false; - } - - if (assembly.AvaloniaResources.TryGetValue(path, out assetDescriptor)) - { - return true; - } - } - } - - return false; - } - - private static bool TryGetResAsmAndPath(Uri uri, [NotNullWhen(true)] out IAssemblyDescriptor? assembly, out string path) - { - path = uri.GetUnescapeAbsolutePath(); - - if (TryLoadAssembly(uri.Authority, out assembly)) - { - return true; - } - - return false; - } - - private static bool TryGetAssembly(Uri? uri, [NotNullWhen(true)] out IAssemblyDescriptor? assembly) - { - assembly = null; - - if (uri != null) - { - if (!uri.IsAbsoluteUri) - { - return false; - } - - if (uri.IsAvares() && TryGetResAsmAndPath(uri, out assembly, out _)) - { - return true; - } - - if (uri.IsResm()) - { - var assemblyName = uri.GetAssemblyNameFromQuery(); - - if (assemblyName.Length > 0 && TryLoadAssembly(assemblyName, out assembly)) - { - return true; - } - } - } - - return false; - } - - private static bool TryLoadAssembly(string assemblyName, [NotNullWhen(true)] out IAssemblyDescriptor? assembly) - { - assembly = null; - - try - { - assembly = s_assemblyDescriptorResolver.GetAssembly(assemblyName); - - return true; - } - catch (Exception) { } - - return false; - } + /// + public static IEnumerable GetAssets(Uri uri, Uri? baseUri) + => GetAssetLoader().GetAssets(uri, baseUri); #endif - public static void RegisterResUriParsers() - { - if (!UriParser.IsKnownScheme("avares")) - UriParser.Register(new GenericUriParser( - GenericUriParserOptions.GenericAuthority | - GenericUriParserOptions.NoUserInfo | - GenericUriParserOptions.NoPort | - GenericUriParserOptions.NoQuery | - GenericUriParserOptions.NoFragment), "avares", -1); - } + internal static void RegisterResUriParsers() + { + if (!UriParser.IsKnownScheme("avares")) + UriParser.Register(new GenericUriParser( + GenericUriParserOptions.GenericAuthority | + GenericUriParserOptions.NoUserInfo | + GenericUriParserOptions.NoPort | + GenericUriParserOptions.NoQuery | + GenericUriParserOptions.NoFragment), "avares", -1); } } diff --git a/src/Avalonia.Base/Platform/StandardAssetLoader.cs b/src/Avalonia.Base/Platform/StandardAssetLoader.cs new file mode 100644 index 0000000000..387f77f59b --- /dev/null +++ b/src/Avalonia.Base/Platform/StandardAssetLoader.cs @@ -0,0 +1,256 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; +using System.Reflection; +using Avalonia.Platform.Internal; +using Avalonia.Utilities; + +namespace Avalonia.Platform +{ + /// + /// Loads assets compiled into the application binary. + /// + internal class StandardAssetLoader : IAssetLoader + { + private readonly IAssemblyDescriptorResolver _assemblyDescriptorResolver; + private AssemblyDescriptor? _defaultResmAssembly; + + public StandardAssetLoader(IAssemblyDescriptorResolver resolver, Assembly? assembly = null) + { + if (assembly == null) + assembly = Assembly.GetEntryAssembly(); + if (assembly != null) + _defaultResmAssembly = new AssemblyDescriptor(assembly); + _assemblyDescriptorResolver = resolver; + } + + public StandardAssetLoader(Assembly? assembly = null) : this(new AssemblyDescriptorResolver(), assembly) + { + + } + + /// + /// Sets the default assembly from which to load assets for which no assembly is specified. + /// + /// The default assembly. + public void SetDefaultAssembly(Assembly assembly) + { + _defaultResmAssembly = new AssemblyDescriptor(assembly); + } + + /// + /// Checks if an asset with the specified URI exists. + /// + /// The URI. + /// + /// A base URI to use if is relative. + /// + /// True if the asset could be found; otherwise false. + public bool Exists(Uri uri, Uri? baseUri = null) + { + return TryGetAsset(uri, baseUri, out _); + } + + /// + /// Opens the asset with the requested URI. + /// + /// The URI. + /// + /// A base URI to use if is relative. + /// + /// A stream containing the asset contents. + /// + /// The asset could not be found. + /// + public Stream Open(Uri uri, Uri? baseUri = null) => OpenAndGetAssembly(uri, baseUri).Item1; + + /// + /// Opens the asset with the requested URI and returns the asset stream and the + /// assembly containing the asset. + /// + /// The URI. + /// + /// A base URI to use if is relative. + /// + /// + /// The stream containing the resource contents together with the assembly. + /// + /// + /// The asset could not be found. + /// + public (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri? baseUri = null) + { + if (TryGetAsset(uri, baseUri, out var assetDescriptor)) + { + return (assetDescriptor.GetStream(), assetDescriptor.Assembly); + } + + throw new FileNotFoundException($"The resource {uri} could not be found."); + } + + public Assembly? GetAssembly(Uri uri, Uri? baseUri) + { + if (!uri.IsAbsoluteUri && baseUri != null) + { + uri = new Uri(baseUri, uri); + } + + if (TryGetAssembly(uri, out var assemblyDescriptor)) + { + return assemblyDescriptor.Assembly; + } + + return null; + } + + /// + /// Gets all assets of a folder and subfolders that match specified uri. + /// + /// The URI. + /// Base URI that is used if is relative. + /// All matching assets as a tuple of the absolute path to the asset and the assembly containing the asset + public IEnumerable GetAssets(Uri uri, Uri? baseUri) + { + if (uri.IsAbsoluteResm()) + { + if (!TryGetAssembly(uri, out var assembly)) + { + assembly = _defaultResmAssembly; + } + + return assembly?.Resources? + .Where(x => x.Key.Contains(uri.GetUnescapeAbsolutePath())) + .Select(x => new Uri($"resm:{x.Key}?assembly={assembly.Name}")) ?? + Enumerable.Empty(); + } + + uri = uri.EnsureAbsolute(baseUri); + + if (uri.IsAvares()) + { + if (!TryGetResAsmAndPath(uri, out var assembly, out var path)) + { + return Enumerable.Empty(); + } + + if (assembly?.AvaloniaResources == null) + { + return Enumerable.Empty(); + } + + if (path.Length > 0 && path[path.Length - 1] != '/') + { + path += '/'; + } + + return assembly.AvaloniaResources + .Where(r => r.Key.StartsWith(path, StringComparison.Ordinal)) + .Select(x => new Uri($"avares://{assembly.Name}{x.Key}")); + } + + return Enumerable.Empty(); + } + + private bool TryGetAsset(Uri uri, Uri? baseUri, [NotNullWhen(true)] out IAssetDescriptor? assetDescriptor) + { + assetDescriptor = null; + + if (uri.IsAbsoluteResm()) + { + if (!TryGetAssembly(uri, out var assembly) && !TryGetAssembly(baseUri, out assembly)) + { + assembly = _defaultResmAssembly; + } + + if (assembly?.Resources != null) + { + var resourceKey = uri.AbsolutePath; + + if (assembly.Resources.TryGetValue(resourceKey, out assetDescriptor)) + { + return true; + } + } + } + + uri = uri.EnsureAbsolute(baseUri); + + if (uri.IsAvares()) + { + if (TryGetResAsmAndPath(uri, out var assembly, out var path)) + { + if (assembly.AvaloniaResources == null) + { + return false; + } + + if (assembly.AvaloniaResources.TryGetValue(path, out assetDescriptor)) + { + return true; + } + } + } + + return false; + } + + private bool TryGetResAsmAndPath(Uri uri, [NotNullWhen(true)] out IAssemblyDescriptor? assembly, out string path) + { + path = uri.GetUnescapeAbsolutePath(); + + if (TryLoadAssembly(uri.Authority, out assembly)) + { + return true; + } + + return false; + } + + private bool TryGetAssembly(Uri? uri, [NotNullWhen(true)] out IAssemblyDescriptor? assembly) + { + assembly = null; + + if (uri != null) + { + if (!uri.IsAbsoluteUri) + { + return false; + } + + if (uri.IsAvares() && TryGetResAsmAndPath(uri, out assembly, out _)) + { + return true; + } + + if (uri.IsResm()) + { + var assemblyName = uri.GetAssemblyNameFromQuery(); + + if (assemblyName.Length > 0 && TryLoadAssembly(assemblyName, out assembly)) + { + return true; + } + } + } + + return false; + } + + private bool TryLoadAssembly(string assemblyName, [NotNullWhen(true)] out IAssemblyDescriptor? assembly) + { + assembly = null; + + try + { + assembly = _assemblyDescriptorResolver.GetAssembly(assemblyName); + + return true; + } + catch (Exception) { } + + return false; + } + } +} diff --git a/src/Avalonia.Base/Platform/StandardRuntimePlatformServices.cs b/src/Avalonia.Base/Platform/StandardRuntimePlatformServices.cs index 0a36b4c9dd..800d9b390f 100644 --- a/src/Avalonia.Base/Platform/StandardRuntimePlatformServices.cs +++ b/src/Avalonia.Base/Platform/StandardRuntimePlatformServices.cs @@ -14,7 +14,7 @@ namespace Avalonia.Platform AssetLoader.RegisterResUriParsers(); AvaloniaLocator.CurrentMutable .Bind().ToConstant(standardPlatform) - .Bind().ToConstant(new AssetLoader(assembly)) + .Bind().ToConstant(new StandardAssetLoader(assembly)) .Bind().ToConstant( #if NET6_0_OR_GREATER new Net6Loader() diff --git a/tests/Avalonia.Base.UnitTests/AssetLoaderTests.cs b/tests/Avalonia.Base.UnitTests/AssetLoaderTests.cs index 894b6578e3..d840ea171e 100644 --- a/tests/Avalonia.Base.UnitTests/AssetLoaderTests.cs +++ b/tests/Avalonia.Base.UnitTests/AssetLoaderTests.cs @@ -7,8 +7,10 @@ using Xunit; namespace Avalonia.Base.UnitTests; -public class AssetLoaderTests : IDisposable +public class AssetLoaderTests { + private IAssemblyDescriptorResolver _resolver; + public class MockAssembly : Assembly { } private const string AssemblyNameWithWhitespace = "Awesome Library"; @@ -17,22 +19,20 @@ public class AssetLoaderTests : IDisposable public AssetLoaderTests() { - var resolver = Mock.Of(); + _resolver = Mock.Of(); var descriptor = CreateAssemblyDescriptor(AssemblyNameWithWhitespace); - Mock.Get(resolver).Setup(x => x.GetAssembly(AssemblyNameWithWhitespace)).Returns(descriptor); + Mock.Get(_resolver).Setup(x => x.GetAssembly(AssemblyNameWithWhitespace)).Returns(descriptor); descriptor = CreateAssemblyDescriptor(AssemblyNameWithNonAscii); - Mock.Get(resolver).Setup(x => x.GetAssembly(AssemblyNameWithNonAscii)).Returns(descriptor); - - AssetLoader.SetAssemblyDescriptorResolver(resolver); + Mock.Get(_resolver).Setup(x => x.GetAssembly(AssemblyNameWithNonAscii)).Returns(descriptor); } [Fact] public void AssemblyName_With_Whitespace_Should_Load_Resm() { var uri = new Uri($"resm:Avalonia.Base.UnitTests.Assets.something?assembly={AssemblyNameWithWhitespace}"); - var loader = new AssetLoader(); + var loader = new StandardAssetLoader(_resolver); var assemblyActual = loader.GetAssembly(uri, null); @@ -43,7 +43,7 @@ public class AssetLoaderTests : IDisposable public void AssemblyName_With_Non_ASCII_Should_Load_Avares() { var uri = new Uri($"avares://{AssemblyNameWithNonAscii}/Assets/something"); - var loader = new AssetLoader(); + var loader = new StandardAssetLoader(_resolver); var assemblyActual = loader.GetAssembly(uri, null); @@ -54,7 +54,7 @@ public class AssetLoaderTests : IDisposable public void Invalid_AssemblyName_Should_Yield_Empty_Enumerable() { var uri = new Uri($"avares://InvalidAssembly"); - var loader = new AssetLoader(); + var loader = new StandardAssetLoader(_resolver); var assemblyActual = loader.GetAssets(uri, null); @@ -71,9 +71,4 @@ public class AssetLoaderTests : IDisposable Mock.Get(descriptor).Setup(x => x.Assembly).Returns(assembly); return descriptor; } - - public void Dispose() - { - AssetLoader.SetAssemblyDescriptorResolver(new AssemblyDescriptorResolver()); - } } diff --git a/tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs b/tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs index b044bcde59..a32f98e462 100644 --- a/tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs +++ b/tests/Avalonia.Benchmarks/Styling/ResourceBenchmarks.cs @@ -17,7 +17,7 @@ namespace Avalonia.Benchmarks.Styling private static IDisposable CreateApp() { var services = new TestServices( - assetLoader: new AssetLoader(), + assetLoader: new StandardAssetLoader(), globalClock: new MockGlobalClock(), platform: new AppBuilder().RuntimePlatform, renderInterface: new MockPlatformRenderInterface(), diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleIncludeTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleIncludeTests.cs index 5d6d4a78e4..67e808221e 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleIncludeTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleIncludeTests.cs @@ -282,7 +282,7 @@ public class StyleIncludeTests public void StyleInclude_From_CodeBehind_Resolves_Compiled() { using var locatorScope = AvaloniaLocator.EnterScope(); - AvaloniaLocator.CurrentMutable.BindToSelf(new AssetLoader(GetType().Assembly)); + AvaloniaLocator.CurrentMutable.BindToSelf(new StandardAssetLoader(GetType().Assembly)); var sp = new TestServiceProvider(); var styleInclude = new StyleInclude(sp) diff --git a/tests/Avalonia.RenderTests/TestBase.cs b/tests/Avalonia.RenderTests/TestBase.cs index 4732099d60..a925b4e60c 100644 --- a/tests/Avalonia.RenderTests/TestBase.cs +++ b/tests/Avalonia.RenderTests/TestBase.cs @@ -45,7 +45,7 @@ namespace Avalonia.Direct2D1.RenderTests private static readonly TestDispatcherImpl threadingInterface = new TestDispatcherImpl(); - private static readonly IAssetLoader assetLoader = new AssetLoader(); + private static readonly IAssetLoader assetLoader = new StandardAssetLoader(); static TestBase() { diff --git a/tests/Avalonia.UnitTests/TestServices.cs b/tests/Avalonia.UnitTests/TestServices.cs index 800abbc2c7..9b95e71d8c 100644 --- a/tests/Avalonia.UnitTests/TestServices.cs +++ b/tests/Avalonia.UnitTests/TestServices.cs @@ -20,7 +20,7 @@ namespace Avalonia.UnitTests public class TestServices { public static readonly TestServices StyledWindow = new TestServices( - assetLoader: new AssetLoader(), + assetLoader: new StandardAssetLoader(), platform: new StandardRuntimePlatform(), renderInterface: new MockPlatformRenderInterface(), standardCursorFactory: Mock.Of(), @@ -31,7 +31,7 @@ namespace Avalonia.UnitTests windowingPlatform: new MockWindowingPlatform()); public static readonly TestServices MockPlatformRenderInterface = new TestServices( - assetLoader: new AssetLoader(), + assetLoader: new StandardAssetLoader(), renderInterface: new MockPlatformRenderInterface(), fontManagerImpl: new MockFontManagerImpl(), textShaperImpl: new MockTextShaperImpl()); @@ -50,13 +50,13 @@ namespace Avalonia.UnitTests keyboardDevice: () => new KeyboardDevice(), keyboardNavigation: new KeyboardNavigationHandler(), inputManager: new InputManager(), - assetLoader: new AssetLoader(), + assetLoader: new StandardAssetLoader(), renderInterface: new MockPlatformRenderInterface(), fontManagerImpl: new MockFontManagerImpl(), textShaperImpl: new MockTextShaperImpl()); public static readonly TestServices TextServices = new TestServices( - assetLoader: new AssetLoader(), + assetLoader: new StandardAssetLoader(), renderInterface: new MockPlatformRenderInterface(), fontManagerImpl: new HarfBuzzFontManagerImpl(), textShaperImpl: new HarfBuzzTextShaperImpl()); From ae3931faa70b9b408cfe00906da01fe3449dcc86 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 29 Apr 2023 23:29:37 -0400 Subject: [PATCH 64/80] Since git decided to mark StandardAssetLoader file as a new, why not fix formatting in here anyway --- .../Platform/StandardAssetLoader.cs | 345 +++++++++--------- 1 file changed, 172 insertions(+), 173 deletions(-) diff --git a/src/Avalonia.Base/Platform/StandardAssetLoader.cs b/src/Avalonia.Base/Platform/StandardAssetLoader.cs index 387f77f59b..118e57c7af 100644 --- a/src/Avalonia.Base/Platform/StandardAssetLoader.cs +++ b/src/Avalonia.Base/Platform/StandardAssetLoader.cs @@ -7,250 +7,249 @@ using System.Reflection; using Avalonia.Platform.Internal; using Avalonia.Utilities; -namespace Avalonia.Platform +namespace Avalonia.Platform; + +/// +/// Loads assets compiled into the application binary. +/// +internal class StandardAssetLoader : IAssetLoader { + private readonly IAssemblyDescriptorResolver _assemblyDescriptorResolver; + private AssemblyDescriptor? _defaultResmAssembly; + + public StandardAssetLoader(IAssemblyDescriptorResolver resolver, Assembly? assembly = null) + { + if (assembly == null) + assembly = Assembly.GetEntryAssembly(); + if (assembly != null) + _defaultResmAssembly = new AssemblyDescriptor(assembly); + _assemblyDescriptorResolver = resolver; + } + + public StandardAssetLoader(Assembly? assembly = null) : this(new AssemblyDescriptorResolver(), assembly) + { + + } + /// - /// Loads assets compiled into the application binary. + /// Sets the default assembly from which to load assets for which no assembly is specified. /// - internal class StandardAssetLoader : IAssetLoader + /// The default assembly. + public void SetDefaultAssembly(Assembly assembly) { - private readonly IAssemblyDescriptorResolver _assemblyDescriptorResolver; - private AssemblyDescriptor? _defaultResmAssembly; + _defaultResmAssembly = new AssemblyDescriptor(assembly); + } - public StandardAssetLoader(IAssemblyDescriptorResolver resolver, Assembly? assembly = null) - { - if (assembly == null) - assembly = Assembly.GetEntryAssembly(); - if (assembly != null) - _defaultResmAssembly = new AssemblyDescriptor(assembly); - _assemblyDescriptorResolver = resolver; - } + /// + /// Checks if an asset with the specified URI exists. + /// + /// The URI. + /// + /// A base URI to use if is relative. + /// + /// True if the asset could be found; otherwise false. + public bool Exists(Uri uri, Uri? baseUri = null) + { + return TryGetAsset(uri, baseUri, out _); + } - public StandardAssetLoader(Assembly? assembly = null) : this(new AssemblyDescriptorResolver(), assembly) + /// + /// Opens the asset with the requested URI. + /// + /// The URI. + /// + /// A base URI to use if is relative. + /// + /// A stream containing the asset contents. + /// + /// The asset could not be found. + /// + public Stream Open(Uri uri, Uri? baseUri = null) => OpenAndGetAssembly(uri, baseUri).Item1; + + /// + /// Opens the asset with the requested URI and returns the asset stream and the + /// assembly containing the asset. + /// + /// The URI. + /// + /// A base URI to use if is relative. + /// + /// + /// The stream containing the resource contents together with the assembly. + /// + /// + /// The asset could not be found. + /// + public (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri? baseUri = null) + { + if (TryGetAsset(uri, baseUri, out var assetDescriptor)) { - + return (assetDescriptor.GetStream(), assetDescriptor.Assembly); } - /// - /// Sets the default assembly from which to load assets for which no assembly is specified. - /// - /// The default assembly. - public void SetDefaultAssembly(Assembly assembly) + throw new FileNotFoundException($"The resource {uri} could not be found."); + } + + public Assembly? GetAssembly(Uri uri, Uri? baseUri) + { + if (!uri.IsAbsoluteUri && baseUri != null) { - _defaultResmAssembly = new AssemblyDescriptor(assembly); + uri = new Uri(baseUri, uri); } - /// - /// Checks if an asset with the specified URI exists. - /// - /// The URI. - /// - /// A base URI to use if is relative. - /// - /// True if the asset could be found; otherwise false. - public bool Exists(Uri uri, Uri? baseUri = null) + if (TryGetAssembly(uri, out var assemblyDescriptor)) { - return TryGetAsset(uri, baseUri, out _); + return assemblyDescriptor.Assembly; } - /// - /// Opens the asset with the requested URI. - /// - /// The URI. - /// - /// A base URI to use if is relative. - /// - /// A stream containing the asset contents. - /// - /// The asset could not be found. - /// - public Stream Open(Uri uri, Uri? baseUri = null) => OpenAndGetAssembly(uri, baseUri).Item1; - - /// - /// Opens the asset with the requested URI and returns the asset stream and the - /// assembly containing the asset. - /// - /// The URI. - /// - /// A base URI to use if is relative. - /// - /// - /// The stream containing the resource contents together with the assembly. - /// - /// - /// The asset could not be found. - /// - public (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri? baseUri = null) + return null; + } + + /// + /// Gets all assets of a folder and subfolders that match specified uri. + /// + /// The URI. + /// Base URI that is used if is relative. + /// All matching assets as a tuple of the absolute path to the asset and the assembly containing the asset + public IEnumerable GetAssets(Uri uri, Uri? baseUri) + { + if (uri.IsAbsoluteResm()) { - if (TryGetAsset(uri, baseUri, out var assetDescriptor)) + if (!TryGetAssembly(uri, out var assembly)) { - return (assetDescriptor.GetStream(), assetDescriptor.Assembly); + assembly = _defaultResmAssembly; } - throw new FileNotFoundException($"The resource {uri} could not be found."); + return assembly?.Resources? + .Where(x => x.Key.Contains(uri.GetUnescapeAbsolutePath())) + .Select(x => new Uri($"resm:{x.Key}?assembly={assembly.Name}")) ?? + Enumerable.Empty(); } - public Assembly? GetAssembly(Uri uri, Uri? baseUri) + uri = uri.EnsureAbsolute(baseUri); + + if (uri.IsAvares()) { - if (!uri.IsAbsoluteUri && baseUri != null) + if (!TryGetResAsmAndPath(uri, out var assembly, out var path)) { - uri = new Uri(baseUri, uri); + return Enumerable.Empty(); } - if (TryGetAssembly(uri, out var assemblyDescriptor)) + if (assembly?.AvaloniaResources == null) { - return assemblyDescriptor.Assembly; + return Enumerable.Empty(); } - return null; + if (path.Length > 0 && path[path.Length - 1] != '/') + { + path += '/'; + } + + return assembly.AvaloniaResources + .Where(r => r.Key.StartsWith(path, StringComparison.Ordinal)) + .Select(x => new Uri($"avares://{assembly.Name}{x.Key}")); } - /// - /// Gets all assets of a folder and subfolders that match specified uri. - /// - /// The URI. - /// Base URI that is used if is relative. - /// All matching assets as a tuple of the absolute path to the asset and the assembly containing the asset - public IEnumerable GetAssets(Uri uri, Uri? baseUri) + return Enumerable.Empty(); + } + + private bool TryGetAsset(Uri uri, Uri? baseUri, [NotNullWhen(true)] out IAssetDescriptor? assetDescriptor) + { + assetDescriptor = null; + + if (uri.IsAbsoluteResm()) { - if (uri.IsAbsoluteResm()) + if (!TryGetAssembly(uri, out var assembly) && !TryGetAssembly(baseUri, out assembly)) { - if (!TryGetAssembly(uri, out var assembly)) - { - assembly = _defaultResmAssembly; - } - - return assembly?.Resources? - .Where(x => x.Key.Contains(uri.GetUnescapeAbsolutePath())) - .Select(x => new Uri($"resm:{x.Key}?assembly={assembly.Name}")) ?? - Enumerable.Empty(); + assembly = _defaultResmAssembly; } - uri = uri.EnsureAbsolute(baseUri); - - if (uri.IsAvares()) + if (assembly?.Resources != null) { - if (!TryGetResAsmAndPath(uri, out var assembly, out var path)) - { - return Enumerable.Empty(); - } - - if (assembly?.AvaloniaResources == null) - { - return Enumerable.Empty(); - } + var resourceKey = uri.AbsolutePath; - if (path.Length > 0 && path[path.Length - 1] != '/') + if (assembly.Resources.TryGetValue(resourceKey, out assetDescriptor)) { - path += '/'; + return true; } - - return assembly.AvaloniaResources - .Where(r => r.Key.StartsWith(path, StringComparison.Ordinal)) - .Select(x => new Uri($"avares://{assembly.Name}{x.Key}")); } - - return Enumerable.Empty(); } - private bool TryGetAsset(Uri uri, Uri? baseUri, [NotNullWhen(true)] out IAssetDescriptor? assetDescriptor) - { - assetDescriptor = null; + uri = uri.EnsureAbsolute(baseUri); - if (uri.IsAbsoluteResm()) + if (uri.IsAvares()) + { + if (TryGetResAsmAndPath(uri, out var assembly, out var path)) { - if (!TryGetAssembly(uri, out var assembly) && !TryGetAssembly(baseUri, out assembly)) + if (assembly.AvaloniaResources == null) { - assembly = _defaultResmAssembly; + return false; } - if (assembly?.Resources != null) + if (assembly.AvaloniaResources.TryGetValue(path, out assetDescriptor)) { - var resourceKey = uri.AbsolutePath; - - if (assembly.Resources.TryGetValue(resourceKey, out assetDescriptor)) - { - return true; - } + return true; } } + } - uri = uri.EnsureAbsolute(baseUri); + return false; + } - if (uri.IsAvares()) - { - if (TryGetResAsmAndPath(uri, out var assembly, out var path)) - { - if (assembly.AvaloniaResources == null) - { - return false; - } - - if (assembly.AvaloniaResources.TryGetValue(path, out assetDescriptor)) - { - return true; - } - } - } + private bool TryGetResAsmAndPath(Uri uri, [NotNullWhen(true)] out IAssemblyDescriptor? assembly, out string path) + { + path = uri.GetUnescapeAbsolutePath(); - return false; + if (TryLoadAssembly(uri.Authority, out assembly)) + { + return true; } - private bool TryGetResAsmAndPath(Uri uri, [NotNullWhen(true)] out IAssemblyDescriptor? assembly, out string path) + return false; + } + + private bool TryGetAssembly(Uri? uri, [NotNullWhen(true)] out IAssemblyDescriptor? assembly) + { + assembly = null; + + if (uri != null) { - path = uri.GetUnescapeAbsolutePath(); + if (!uri.IsAbsoluteUri) + { + return false; + } - if (TryLoadAssembly(uri.Authority, out assembly)) + if (uri.IsAvares() && TryGetResAsmAndPath(uri, out assembly, out _)) { return true; } - return false; - } - - private bool TryGetAssembly(Uri? uri, [NotNullWhen(true)] out IAssemblyDescriptor? assembly) - { - assembly = null; - - if (uri != null) + if (uri.IsResm()) { - if (!uri.IsAbsoluteUri) - { - return false; - } + var assemblyName = uri.GetAssemblyNameFromQuery(); - if (uri.IsAvares() && TryGetResAsmAndPath(uri, out assembly, out _)) + if (assemblyName.Length > 0 && TryLoadAssembly(assemblyName, out assembly)) { return true; } - - if (uri.IsResm()) - { - var assemblyName = uri.GetAssemblyNameFromQuery(); - - if (assemblyName.Length > 0 && TryLoadAssembly(assemblyName, out assembly)) - { - return true; - } - } } - - return false; } - private bool TryLoadAssembly(string assemblyName, [NotNullWhen(true)] out IAssemblyDescriptor? assembly) - { - assembly = null; + return false; + } - try - { - assembly = _assemblyDescriptorResolver.GetAssembly(assemblyName); + private bool TryLoadAssembly(string assemblyName, [NotNullWhen(true)] out IAssemblyDescriptor? assembly) + { + assembly = null; - return true; - } - catch (Exception) { } + try + { + assembly = _assemblyDescriptorResolver.GetAssembly(assemblyName); - return false; + return true; } + catch (Exception) { } + + return false; } } From 8ba233b23facb9cc3784739f543dc996900440d3 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 29 Apr 2023 23:32:18 -0400 Subject: [PATCH 65/80] Fix Screens.ScreenFromWindow API --- src/Avalonia.Controls/Screens.cs | 12 +++++++++++- src/Avalonia.Controls/Window.cs | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/Screens.cs b/src/Avalonia.Controls/Screens.cs index 22f9c0832a..a9f52315f9 100644 --- a/src/Avalonia.Controls/Screens.cs +++ b/src/Avalonia.Controls/Screens.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using Avalonia.Platform; -using Avalonia.VisualTree; #nullable enable @@ -43,6 +42,17 @@ namespace Avalonia.Controls return _iScreenImpl.ScreenFromRect(bounds); } + public Screen? ScreenFromWindow(WindowBase window) + { + if (window.PlatformImpl is null) + { + throw new ObjectDisposedException("Window platform implementation was already disposed."); + } + + return _iScreenImpl.ScreenFromWindow(window.PlatformImpl); + } + + [Obsolete("Use ScreenFromWindow(WindowBase) overload.")] public Screen? ScreenFromWindow(IWindowBaseImpl window) { return _iScreenImpl.ScreenFromWindow(window); diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index 48edb81b16..66cce89b9d 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -713,7 +713,7 @@ namespace Avalonia.Controls Owner = owner; owner?.AddChild(this, false); - SetWindowStartupLocation(owner?.PlatformImpl); + SetWindowStartupLocation(owner); PlatformImpl?.Show(ShowActivated, false); Renderer.Start(); @@ -789,7 +789,7 @@ namespace Avalonia.Controls Owner = owner; owner.AddChild(this, true); - SetWindowStartupLocation(owner.PlatformImpl); + SetWindowStartupLocation(owner); PlatformImpl?.Show(ShowActivated, true); @@ -870,7 +870,7 @@ namespace Avalonia.Controls } } - private void SetWindowStartupLocation(IWindowBaseImpl? owner = null) + private void SetWindowStartupLocation(Window? owner = null) { var startupLocation = WindowStartupLocation; From 009000123ff1e35ee0bdbb7c5efb5f7ab0ccf3aa Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 29 Apr 2023 23:41:47 -0400 Subject: [PATCH 66/80] Update Screens docs --- src/Avalonia.Controls/Screens.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Screens.cs b/src/Avalonia.Controls/Screens.cs index a9f52315f9..60d5358c49 100644 --- a/src/Avalonia.Controls/Screens.cs +++ b/src/Avalonia.Controls/Screens.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Avalonia.Platform; @@ -37,11 +37,22 @@ namespace Avalonia.Controls _iScreenImpl = iScreenImpl; } + /// + /// Retrieves a Screen for the display that contains the rectangle. + /// + /// Bounds that specifies the area for which to retrieve the display. + /// The . public Screen? ScreenFromBounds(PixelRect bounds) { return _iScreenImpl.ScreenFromRect(bounds); } + /// + /// Retrieves a Screen for the display that contains the specified . + /// + /// The window for which to retrieve the Screen. + /// Window platform implementation was already disposed. + /// The . public Screen? ScreenFromWindow(WindowBase window) { if (window.PlatformImpl is null) @@ -52,17 +63,32 @@ namespace Avalonia.Controls return _iScreenImpl.ScreenFromWindow(window.PlatformImpl); } + /// + /// Retrieves a Screen for the display that contains the specified . + /// + /// The window impl for which to retrieve the Screen. + /// The . [Obsolete("Use ScreenFromWindow(WindowBase) overload.")] public Screen? ScreenFromWindow(IWindowBaseImpl window) { return _iScreenImpl.ScreenFromWindow(window); } + /// + /// Retrieves a Screen for the display that contains the specified point. + /// + /// A Point that specifies the location for which to retrieve a Screen. + /// The . public Screen? ScreenFromPoint(PixelPoint point) { return _iScreenImpl.ScreenFromPoint(point); } + /// + /// Retrieves a Screen for the display that contains the specified . + /// + /// A Visual for which to retrieve a Screen. + /// The . public Screen? ScreenFromVisual(Visual visual) { var tl = visual.PointToScreen(visual.Bounds.TopLeft); From a11bef715b283b99adb535dfa857e039573bce1f Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 29 Apr 2023 23:44:21 -0400 Subject: [PATCH 67/80] Add Message parameter to the Unstable attribute --- nukebuild/RefAssemblyGenerator.cs | 24 ++++++++++++------- .../Metadata/UnstableAttribute.cs | 22 ++++++++++++++++- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/nukebuild/RefAssemblyGenerator.cs b/nukebuild/RefAssemblyGenerator.cs index cbe5236bca..f0d5c81a37 100644 --- a/nukebuild/RefAssemblyGenerator.cs +++ b/nukebuild/RefAssemblyGenerator.cs @@ -96,7 +96,7 @@ public class RefAssemblyGenerator | MethodAttributes.HideBySig, type.Module.TypeSystem.Void)); } - var forceUnstable = type.CustomAttributes.Any(a => + var forceUnstable = type.CustomAttributes.FirstOrDefault(a => a.AttributeType.FullName == "Avalonia.Metadata.UnstableAttribute"); foreach (var m in type.Methods) @@ -109,22 +109,28 @@ public class RefAssemblyGenerator } } - static void MarkAsUnstable(IMemberDefinition def, MethodReference obsoleteCtor, bool force) + static void MarkAsUnstable(IMemberDefinition def, MethodReference obsoleteCtor, ICustomAttribute unstableAttribute) { - if (!force && ( - def.HasCustomAttributes == false - || def.CustomAttributes.All(a => a.AttributeType.FullName != "Avalonia.Metadata.UnstableAttribute"))) + if (def.CustomAttributes.Any(a => a.AttributeType.FullName == "System.ObsoleteAttribute")) return; - if (def.CustomAttributes.Any(a => a.AttributeType.FullName == "System.ObsoleteAttribute")) + unstableAttribute = def.CustomAttributes.FirstOrDefault(a => + a.AttributeType.FullName == "Avalonia.Metadata.UnstableAttribute") ?? unstableAttribute; + + if (unstableAttribute is null) return; + var message = unstableAttribute.ConstructorArguments.FirstOrDefault().Value?.ToString(); + if (string.IsNullOrEmpty(message)) + { + message = "This is a part of unstable API and can be changed in minor releases. Consider replacing it with alternatives or reach out developers on GitHub."; + } + def.CustomAttributes.Add(new CustomAttribute(obsoleteCtor) { ConstructorArguments = { - new CustomAttributeArgument(obsoleteCtor.Module.TypeSystem.String, - "This is a part of unstable API and can be changed in minor releases. You have been warned") + new CustomAttributeArgument(obsoleteCtor.Module.TypeSystem.String, message) } }); } @@ -168,4 +174,4 @@ public class RefAssemblyGenerator } } } -} \ No newline at end of file +} diff --git a/src/Avalonia.Base/Metadata/UnstableAttribute.cs b/src/Avalonia.Base/Metadata/UnstableAttribute.cs index 361f6d30fd..bbb298f7a6 100644 --- a/src/Avalonia.Base/Metadata/UnstableAttribute.cs +++ b/src/Avalonia.Base/Metadata/UnstableAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Avalonia.Metadata { @@ -9,5 +9,25 @@ namespace Avalonia.Metadata [AttributeUsage(AttributeTargets.All)] public sealed class UnstableAttribute : Attribute { + /// + /// Initializes a new instance of the class. + /// + public UnstableAttribute() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The text string that describes alternative workarounds. + public UnstableAttribute(string? message) + { + Message = message; + } + + /// + /// Gets a value that indicates whether the compiler will treat usage of the obsolete program element as an error. + /// + public string? Message { get; } } } From bbeef11aeddf8283efeb4bbdb7873f5863d29e56 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 29 Apr 2023 23:44:49 -0400 Subject: [PATCH 68/80] Adjust some Unstable attr usages --- src/Avalonia.Base/Controls/IThemeVariantProvider.cs | 3 +-- src/Avalonia.Base/Input/DragEventArgs.cs | 3 +-- src/Avalonia.Base/Input/PointerDeltaEventArgs.cs | 3 +-- src/Avalonia.Base/Input/PointerEventArgs.cs | 12 ++++-------- src/Avalonia.Base/Input/PointerWheelEventArgs.cs | 3 +-- src/Avalonia.Base/Platform/IAssetLoader.cs | 2 +- 6 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Avalonia.Base/Controls/IThemeVariantProvider.cs b/src/Avalonia.Base/Controls/IThemeVariantProvider.cs index d1dca2efbf..03a7fb1206 100644 --- a/src/Avalonia.Base/Controls/IThemeVariantProvider.cs +++ b/src/Avalonia.Base/Controls/IThemeVariantProvider.cs @@ -10,9 +10,8 @@ namespace Avalonia.Controls; /// /// This is a helper interface for the XAML compiler to make Key property accessibly by the markup extensions. /// Which means, it can only be used with ResourceDictionaries and markup extensions in the XAML code. -/// This API might be removed in the future minor updates. /// -[Unstable] +[Unstable("This XAML-only API might be removed in the future minor updates.")] public interface IThemeVariantProvider : IResourceProvider { /// diff --git a/src/Avalonia.Base/Input/DragEventArgs.cs b/src/Avalonia.Base/Input/DragEventArgs.cs index 8d7cc2b9a1..26ec98361b 100644 --- a/src/Avalonia.Base/Input/DragEventArgs.cs +++ b/src/Avalonia.Base/Input/DragEventArgs.cs @@ -25,8 +25,7 @@ namespace Avalonia.Input return _target.TranslatePoint(_targetLocation, relativeTo) ?? new Point(0, 0); } - [Unstable] - [Obsolete("This constructor might be removed in 12.0. For unit testing, consider using DragDrop.DoDragDrop or IHeadlessWindow.DragDrop.")] + [Unstable("This constructor might be removed in 12.0. For unit testing, consider using DragDrop.DoDragDrop or IHeadlessWindow.DragDrop.")] public DragEventArgs(RoutedEvent routedEvent, IDataObject data, Interactive target, Point targetLocation, KeyModifiers keyModifiers) : base(routedEvent) { diff --git a/src/Avalonia.Base/Input/PointerDeltaEventArgs.cs b/src/Avalonia.Base/Input/PointerDeltaEventArgs.cs index c405cdfacd..3c4562edf4 100644 --- a/src/Avalonia.Base/Input/PointerDeltaEventArgs.cs +++ b/src/Avalonia.Base/Input/PointerDeltaEventArgs.cs @@ -9,8 +9,7 @@ namespace Avalonia.Input { public Vector Delta { get; } - [Unstable] - [Obsolete("This constructor might be removed in 12.0.")] + [Unstable("This constructor might be removed in 12.0.")] public PointerDeltaEventArgs(RoutedEvent routedEvent, object? source, IPointer pointer, Visual rootVisual, Point rootVisualPosition, ulong timestamp, PointerPointProperties properties, KeyModifiers modifiers, Vector delta) diff --git a/src/Avalonia.Base/Input/PointerEventArgs.cs b/src/Avalonia.Base/Input/PointerEventArgs.cs index beb953ce8f..7f82199b56 100644 --- a/src/Avalonia.Base/Input/PointerEventArgs.cs +++ b/src/Avalonia.Base/Input/PointerEventArgs.cs @@ -14,8 +14,7 @@ namespace Avalonia.Input private readonly PointerPointProperties _properties; private readonly Lazy?>? _previousPoints; - [Unstable] - [Obsolete("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")] + [Unstable("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")] public PointerEventArgs(RoutedEvent routedEvent, object? source, IPointer pointer, @@ -129,8 +128,7 @@ namespace Avalonia.Input public class PointerPressedEventArgs : PointerEventArgs { - [Unstable] - [Obsolete("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")] + [Unstable("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")] public PointerPressedEventArgs( object source, IPointer pointer, @@ -150,8 +148,7 @@ namespace Avalonia.Input public class PointerReleasedEventArgs : PointerEventArgs { - [Unstable] - [Obsolete("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")] + [Unstable("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow mouse methods.")] public PointerReleasedEventArgs( object source, IPointer pointer, Visual rootVisual, Point rootVisualPosition, ulong timestamp, @@ -173,8 +170,7 @@ namespace Avalonia.Input { public IPointer Pointer { get; } - [Unstable] - [Obsolete("This constructor might be removed in 12.0. If you need to remove capture, use stable methods on the IPointer instance.,")] + [Unstable("This constructor might be removed in 12.0. If you need to remove capture, use stable methods on the IPointer instance.,")] public PointerCaptureLostEventArgs(object source, IPointer pointer) : base(InputElement.PointerCaptureLostEvent) { Pointer = pointer; diff --git a/src/Avalonia.Base/Input/PointerWheelEventArgs.cs b/src/Avalonia.Base/Input/PointerWheelEventArgs.cs index 903019d85d..22624a61dd 100644 --- a/src/Avalonia.Base/Input/PointerWheelEventArgs.cs +++ b/src/Avalonia.Base/Input/PointerWheelEventArgs.cs @@ -9,8 +9,7 @@ namespace Avalonia.Input { public Vector Delta { get; } - [Unstable] - [Obsolete("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow.MouseWheel.")] + [Unstable("This constructor might be removed in 12.0. For unit testing, consider using IHeadlessWindow.MouseWheel.")] public PointerWheelEventArgs(object source, IPointer pointer, Visual rootVisual, Point rootVisualPosition, ulong timestamp, PointerPointProperties properties, KeyModifiers modifiers, Vector delta) diff --git a/src/Avalonia.Base/Platform/IAssetLoader.cs b/src/Avalonia.Base/Platform/IAssetLoader.cs index b65d61803f..f1ce624c70 100644 --- a/src/Avalonia.Base/Platform/IAssetLoader.cs +++ b/src/Avalonia.Base/Platform/IAssetLoader.cs @@ -9,7 +9,7 @@ namespace Avalonia.Platform /// /// Loads assets compiled into the application binary. /// - [Unstable] + [Unstable("IAssetLoader interface and AvaloniaLocator usage is considered unstable. Please use AssetLoader static class instead.")] public interface IAssetLoader { /// From 04ff14f0cde3b93d29a4239dc1ca5bf9d36ccb26 Mon Sep 17 00:00:00 2001 From: Max Katz Date: Sat, 29 Apr 2023 23:58:59 -0400 Subject: [PATCH 69/80] Return WriteableBitmap from the GetLastRenderedFrame API --- src/Headless/Avalonia.Headless/HeadlessWindowExtensions.cs | 4 ++-- src/Headless/Avalonia.Headless/HeadlessWindowImpl.cs | 4 ++-- src/Headless/Avalonia.Headless/IHeadlessWindow.cs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Headless/Avalonia.Headless/HeadlessWindowExtensions.cs b/src/Headless/Avalonia.Headless/HeadlessWindowExtensions.cs index 8fbc5ec6ef..7d4b7f5477 100644 --- a/src/Headless/Avalonia.Headless/HeadlessWindowExtensions.cs +++ b/src/Headless/Avalonia.Headless/HeadlessWindowExtensions.cs @@ -17,7 +17,7 @@ public static class HeadlessWindowExtensions /// Triggers a renderer timer tick and captures last rendered frame. /// /// Bitmap with last rendered frame. Null, if nothing was rendered. - public static Bitmap? CaptureRenderedFrame(this TopLevel topLevel) + public static WriteableBitmap? CaptureRenderedFrame(this TopLevel topLevel) { Dispatcher.UIThread.RunJobs(); AvaloniaHeadlessPlatform.ForceRenderTimerTick(); @@ -29,7 +29,7 @@ public static class HeadlessWindowExtensions /// Note, in order to trigger rendering timer, call method. /// /// Bitmap with last rendered frame. Null, if nothing was rendered. - public static Bitmap? GetLastRenderedFrame(this TopLevel topLevel) + public static WriteableBitmap? GetLastRenderedFrame(this TopLevel topLevel) { if (AvaloniaLocator.Current.GetService() is HeadlessPlatformRenderInterface) { diff --git a/src/Headless/Avalonia.Headless/HeadlessWindowImpl.cs b/src/Headless/Avalonia.Headless/HeadlessWindowImpl.cs index b15c1eb327..93f92d46f8 100644 --- a/src/Headless/Avalonia.Headless/HeadlessWindowImpl.cs +++ b/src/Headless/Avalonia.Headless/HeadlessWindowImpl.cs @@ -214,7 +214,7 @@ namespace Avalonia.Headless }); } - public Bitmap? GetLastRenderedFrame() + public WriteableBitmap? GetLastRenderedFrame() { lock (_sync) { @@ -224,7 +224,7 @@ namespace Avalonia.Headless } using var lockedFramebuffer = _lastRenderedFrame.Lock(); - return new Bitmap(lockedFramebuffer.Format, AlphaFormat.Opaque, lockedFramebuffer.Address, + return new WriteableBitmap(lockedFramebuffer.Format, AlphaFormat.Opaque, lockedFramebuffer.Address, lockedFramebuffer.Size, lockedFramebuffer.Dpi, lockedFramebuffer.RowBytes); } } diff --git a/src/Headless/Avalonia.Headless/IHeadlessWindow.cs b/src/Headless/Avalonia.Headless/IHeadlessWindow.cs index f3da2335bc..ef501b3800 100644 --- a/src/Headless/Avalonia.Headless/IHeadlessWindow.cs +++ b/src/Headless/Avalonia.Headless/IHeadlessWindow.cs @@ -8,7 +8,7 @@ namespace Avalonia.Headless { internal interface IHeadlessWindow { - Bitmap? GetLastRenderedFrame(); + WriteableBitmap? GetLastRenderedFrame(); void KeyPress(Key key, RawInputModifiers modifiers); void KeyRelease(Key key, RawInputModifiers modifiers); void MouseDown(Point point, MouseButton button, RawInputModifiers modifiers = RawInputModifiers.None); From 8c31885a3da900ceec88a4b2a891949e9274cdc4 Mon Sep 17 00:00:00 2001 From: robloo Date: Sun, 30 Apr 2023 11:32:04 -0400 Subject: [PATCH 70/80] Fix several issues with comments in Dispatcher.Invoke.cs --- .../Threading/Dispatcher.Invoke.cs | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/Avalonia.Base/Threading/Dispatcher.Invoke.cs b/src/Avalonia.Base/Threading/Dispatcher.Invoke.cs index 6842e4a255..699186868a 100644 --- a/src/Avalonia.Base/Threading/Dispatcher.Invoke.cs +++ b/src/Avalonia.Base/Threading/Dispatcher.Invoke.cs @@ -1,5 +1,4 @@ using System; -using System.ComponentModel; using System.Diagnostics; using System.Threading; using System.Threading.Tasks; @@ -118,11 +117,11 @@ public partial class Dispatcher } /// - /// Executes the specified Func synchronously on the + /// Executes the specified Func<TResult> synchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The return value from the delegate being invoked. @@ -136,11 +135,11 @@ public partial class Dispatcher } /// - /// Executes the specified Func synchronously on the + /// Executes the specified Func<TResult> synchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -156,11 +155,11 @@ public partial class Dispatcher } /// - /// Executes the specified Func synchronously on the + /// Executes the specified Func<TResult> synchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -183,11 +182,11 @@ public partial class Dispatcher } /// - /// Executes the specified Func synchronously on the + /// Executes the specified Func<TResult> synchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -317,11 +316,11 @@ public partial class Dispatcher } /// - /// Executes the specified Func asynchronously on the + /// Executes the specified Func<TResult> asynchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// An operation representing the queued delegate to be invoked. @@ -335,11 +334,11 @@ public partial class Dispatcher } /// - /// Executes the specified Func asynchronously on the + /// Executes the specified Func<TResult> asynchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -355,11 +354,11 @@ public partial class Dispatcher } /// - /// Executes the specified Func asynchronously on the + /// Executes the specified Func<TResult> asynchronously on the /// thread that the Dispatcher was created on. /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<TResult> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -479,7 +478,7 @@ public partial class Dispatcher // operation has already started when the timeout expires, // we still wait for it to complete. This is different // than simply waiting on the operation with a timeout - // because we are the ones queueing the dispatcher + // because we are the ones queuing the dispatcher // operation, not the caller. We can't leave the operation // in a state that it might execute if we return that it did not // invoke. @@ -492,12 +491,12 @@ public partial class Dispatcher // Old async semantics return from Wait without // throwing an exception if the operation was aborted. - // There is no need to test the timout condition, since + // There is no need to test the timeout condition, since // the old async semantics would just return the result, // which would be null. // This should not block because either the operation - // is using the old async sematics, or the operation + // is using the old async semantics, or the operation // completed successfully. result = operation.GetResult(); } @@ -543,11 +542,11 @@ public partial class Dispatcher } /// - /// Executes the specified Func asynchronously on the + /// Executes the specified Func<Task> asynchronously on the /// thread that the Dispatcher was created on /// /// - /// A Func delegate to invoke through the dispatcher. + /// A Func<Task> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -564,11 +563,11 @@ public partial class Dispatcher } /// - /// Executes the specified Func> asynchronously on the + /// Executes the specified Func<Task<TResult>> asynchronously on the /// thread that the Dispatcher was created on /// - /// - /// A Func> delegate to invoke through the dispatcher. + /// + /// A Func<Task<TResult>> delegate to invoke through the dispatcher. /// /// /// The priority that determines in what order the specified @@ -595,4 +594,4 @@ public partial class Dispatcher _ = action ?? throw new ArgumentNullException(nameof(action)); InvokeAsyncImpl(new SendOrPostCallbackDispatcherOperation(this, priority, action, arg, true), CancellationToken.None); } -} \ No newline at end of file +} From b96f9abd06e866145080e51d74379749e4dc6a97 Mon Sep 17 00:00:00 2001 From: robloo Date: Sun, 30 Apr 2023 12:05:43 -0400 Subject: [PATCH 71/80] Update ProgressBar TemplateSettings and comments --- src/Avalonia.Controls/ProgressBar.cs | 95 +++++++++++++++---- .../Controls/ProgressBar.xaml | 32 +++---- .../Controls/ProgressBar.xaml | 4 +- 3 files changed, 92 insertions(+), 39 deletions(-) diff --git a/src/Avalonia.Controls/ProgressBar.cs b/src/Avalonia.Controls/ProgressBar.cs index daf6be12d2..7dcdaa2f8d 100644 --- a/src/Avalonia.Controls/ProgressBar.cs +++ b/src/Avalonia.Controls/ProgressBar.cs @@ -17,7 +17,13 @@ namespace Avalonia.Controls [PseudoClasses(":vertical", ":horizontal", ":indeterminate")] public class ProgressBar : RangeBase { - public class ProgressBarTemplateProperties : AvaloniaObject + /// + /// Provides calculated values for use with the 's control theme or template. + /// + /// + /// This class is NOT intended for general use outside of control templates. + /// + public class ProgressBarTemplateSettings : AvaloniaObject { private double _container2Width; private double _containerWidth; @@ -26,38 +32,38 @@ namespace Avalonia.Controls private double _container2AnimationStartPosition; private double _container2AnimationEndPosition; - public static readonly DirectProperty ContainerAnimationStartPositionProperty = - AvaloniaProperty.RegisterDirect( + public static readonly DirectProperty ContainerAnimationStartPositionProperty = + AvaloniaProperty.RegisterDirect( nameof(ContainerAnimationStartPosition), p => p.ContainerAnimationStartPosition, (p, o) => p.ContainerAnimationStartPosition = o, 0d); - public static readonly DirectProperty ContainerAnimationEndPositionProperty = - AvaloniaProperty.RegisterDirect( + public static readonly DirectProperty ContainerAnimationEndPositionProperty = + AvaloniaProperty.RegisterDirect( nameof(ContainerAnimationEndPosition), p => p.ContainerAnimationEndPosition, (p, o) => p.ContainerAnimationEndPosition = o, 0d); - public static readonly DirectProperty Container2AnimationStartPositionProperty = - AvaloniaProperty.RegisterDirect( + public static readonly DirectProperty Container2AnimationStartPositionProperty = + AvaloniaProperty.RegisterDirect( nameof(Container2AnimationStartPosition), p => p.Container2AnimationStartPosition, (p, o) => p.Container2AnimationStartPosition = o, 0d); - public static readonly DirectProperty Container2AnimationEndPositionProperty = - AvaloniaProperty.RegisterDirect( + public static readonly DirectProperty Container2AnimationEndPositionProperty = + AvaloniaProperty.RegisterDirect( nameof(Container2AnimationEndPosition), p => p.Container2AnimationEndPosition, (p, o) => p.Container2AnimationEndPosition = o); - public static readonly DirectProperty Container2WidthProperty = - AvaloniaProperty.RegisterDirect( + public static readonly DirectProperty Container2WidthProperty = + AvaloniaProperty.RegisterDirect( nameof(Container2Width), p => p.Container2Width, (p, o) => p.Container2Width = o); - public static readonly DirectProperty ContainerWidthProperty = - AvaloniaProperty.RegisterDirect( + public static readonly DirectProperty ContainerWidthProperty = + AvaloniaProperty.RegisterDirect( nameof(ContainerWidth), p => p.ContainerWidth, (p, o) => p.ContainerWidth = o); @@ -103,29 +109,57 @@ namespace Avalonia.Controls private Border? _indicator; private IDisposable? _trackSizeChangedListener; + /// + /// Defines the property. + /// public static readonly StyledProperty IsIndeterminateProperty = AvaloniaProperty.Register(nameof(IsIndeterminate)); + /// + /// Defines the property. + /// public static readonly StyledProperty ShowProgressTextProperty = AvaloniaProperty.Register(nameof(ShowProgressText)); + /// + /// Defines the property. + /// public static readonly StyledProperty ProgressTextFormatProperty = AvaloniaProperty.Register(nameof(ProgressTextFormat), "{1:0}%"); + /// + /// Defines the property. + /// public static readonly StyledProperty OrientationProperty = AvaloniaProperty.Register(nameof(Orientation), Orientation.Horizontal); + /// + /// Defines the property. + /// public static readonly DirectProperty PercentageProperty = AvaloniaProperty.RegisterDirect( nameof(Percentage), o => o.Percentage); + /// + /// Defines the property. + /// public static readonly StyledProperty IndeterminateStartingOffsetProperty = AvaloniaProperty.Register(nameof(IndeterminateStartingOffset)); + /// + /// Defines the property. + /// public static readonly StyledProperty IndeterminateEndingOffsetProperty = AvaloniaProperty.Register(nameof(IndeterminateEndingOffset)); + /// + /// Gets the overall percentage complete of the progress + /// + /// + /// This read-only property is automatically calculated using the current and + /// the effective range ( - ). + /// public double Percentage { get { return _percentage; } @@ -154,31 +188,50 @@ namespace Avalonia.Controls OrientationProperty.Changed.AddClassHandler((x, e) => x.UpdateIndicatorWhenPropChanged(e)); } + /// + /// Initializes a new instance of the class. + /// public ProgressBar() { UpdatePseudoClasses(IsIndeterminate, Orientation); } - public ProgressBarTemplateProperties TemplateProperties { get; } = new ProgressBarTemplateProperties(); + /// + /// Gets or sets the TemplateSettings for the . + /// + public ProgressBarTemplateSettings TemplateSettings { get; } = new ProgressBarTemplateSettings(); + /// + /// Gets or sets a value indicating whether the progress bar shows the actual value or a generic, + /// continues progress indicator (indeterminate state). + /// public bool IsIndeterminate { get => GetValue(IsIndeterminateProperty); set => SetValue(IsIndeterminateProperty, value); } + /// + /// Gets or sets a value indicating whether progress text will be shown. + /// public bool ShowProgressText { get => GetValue(ShowProgressTextProperty); set => SetValue(ShowProgressTextProperty, value); } + /// + /// Gets or sets the format string applied to the internally calculated progress text before it is shown. + /// public string ProgressTextFormat { get => GetValue(ProgressTextFormatProperty); set => SetValue(ProgressTextFormatProperty, value); } + /// + /// Gets or sets the orientation of the . + /// public Orientation Orientation { get => GetValue(OrientationProperty); @@ -193,6 +246,7 @@ namespace Avalonia.Controls return result; } + /// protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { base.OnPropertyChanged(change); @@ -242,15 +296,14 @@ namespace Avalonia.Controls var barIndicatorWidth = dim * 0.4; // Indicator width at 40% of ProgressBar var barIndicatorWidth2 = dim * 0.6; // Indicator width at 60% of ProgressBar - TemplateProperties.ContainerWidth = barIndicatorWidth; - TemplateProperties.Container2Width = barIndicatorWidth2; - - TemplateProperties.ContainerAnimationStartPosition = barIndicatorWidth * -1.8; // Position at -180% - TemplateProperties.ContainerAnimationEndPosition = barIndicatorWidth * 3.0; // Position at 300% + TemplateSettings.ContainerWidth = barIndicatorWidth; + TemplateSettings.Container2Width = barIndicatorWidth2; - TemplateProperties.Container2AnimationStartPosition = barIndicatorWidth2 * -1.5; // Position at -150% - TemplateProperties.Container2AnimationEndPosition = barIndicatorWidth2 * 1.66; // Position at 166% + TemplateSettings.ContainerAnimationStartPosition = barIndicatorWidth * -1.8; // Position at -180% + TemplateSettings.ContainerAnimationEndPosition = barIndicatorWidth * 3.0; // Position at 300% + TemplateSettings.Container2AnimationStartPosition = barIndicatorWidth2 * -1.5; // Position at -150% + TemplateSettings.Container2AnimationEndPosition = barIndicatorWidth2 * 1.66; // Position at 166% // Remove these properties when we switch to fluent as default and removed the old one. SetCurrentValue(IndeterminateStartingOffsetProperty,-dim); diff --git a/src/Avalonia.Themes.Fluent/Controls/ProgressBar.xaml b/src/Avalonia.Themes.Fluent/Controls/ProgressBar.xaml index 253d85852e..64a598e359 100644 --- a/src/Avalonia.Themes.Fluent/Controls/ProgressBar.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/ProgressBar.xaml @@ -125,13 +125,13 @@ - + - + - + @@ -140,13 +140,13 @@ - + - + - + @@ -155,13 +155,13 @@ - + - + - + @@ -170,28 +170,28 @@ - + - + - + diff --git a/src/Avalonia.Themes.Simple/Controls/ProgressBar.xaml b/src/Avalonia.Themes.Simple/Controls/ProgressBar.xaml index 3eb158d5b6..1f4bf006a0 100644 --- a/src/Avalonia.Themes.Simple/Controls/ProgressBar.xaml +++ b/src/Avalonia.Themes.Simple/Controls/ProgressBar.xaml @@ -93,7 +93,7 @@ - + From 24a92e73e7ae022fde9470177b05f56fb32e0b2d Mon Sep 17 00:00:00 2001 From: robloo Date: Sun, 30 Apr 2023 12:06:03 -0400 Subject: [PATCH 72/80] Update SplitView comments based on ProgressBar changes --- src/Avalonia.Controls/SplitView/SplitView.cs | 6 +++--- .../SplitView/SplitViewTemplateSettings.cs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/SplitView/SplitView.cs b/src/Avalonia.Controls/SplitView/SplitView.cs index 8060ca9594..3ad656ee3c 100644 --- a/src/Avalonia.Controls/SplitView/SplitView.cs +++ b/src/Avalonia.Controls/SplitView/SplitView.cs @@ -217,8 +217,8 @@ namespace Avalonia.Controls /// /// Gets or sets whether WinUI equivalent LightDismissOverlayMode is enabled /// When enabled, and the pane is open in Overlay or CompactOverlay mode, - /// the contents of the splitview are darkened to visually separate the open pane - /// and the rest of the SplitView + /// the contents of the are darkened to visually separate the open pane + /// and the rest of the . /// public bool UseLightDismissOverlayMode { @@ -227,7 +227,7 @@ namespace Avalonia.Controls } /// - /// Gets or sets the TemplateSettings for the SplitView + /// Gets or sets the TemplateSettings for the . /// public SplitViewTemplateSettings TemplateSettings { diff --git a/src/Avalonia.Controls/SplitView/SplitViewTemplateSettings.cs b/src/Avalonia.Controls/SplitView/SplitViewTemplateSettings.cs index 8c59de7420..1794b9260f 100644 --- a/src/Avalonia.Controls/SplitView/SplitViewTemplateSettings.cs +++ b/src/Avalonia.Controls/SplitView/SplitViewTemplateSettings.cs @@ -2,8 +2,10 @@ { /// /// Provides calculated values for use with the 's control theme or template. - /// This class is NOT intended for general use. /// + /// + /// This class is NOT intended for general use outside of control templates. + /// public class SplitViewTemplateSettings : AvaloniaObject { internal SplitViewTemplateSettings() { } From 9d76cdd3ddb7440dbaffe868eac833ed5071380c Mon Sep 17 00:00:00 2001 From: robloo Date: Sun, 30 Apr 2023 12:18:59 -0400 Subject: [PATCH 73/80] Rename incorrect `Color.ToUint32` to `ToUInt32` --- .../RenderDemo/Pages/WriteableBitmapPage.cs | 2 +- src/Avalonia.Base/Media/Color.cs | 11 +++- src/Avalonia.Base/Media/GeometryDrawing.cs | 2 +- .../AvaloniaXamlIlLanguageParseIntrinsics.cs | 4 +- .../DynamicResourceExtensionTests.cs | 52 +++++++++---------- .../MarkupExtensions/ResourceIncludeTests.cs | 2 +- .../StaticResourceExtensionTests.cs | 32 ++++++------ .../Xaml/StyleTests.cs | 4 +- 8 files changed, 58 insertions(+), 51 deletions(-) diff --git a/samples/RenderDemo/Pages/WriteableBitmapPage.cs b/samples/RenderDemo/Pages/WriteableBitmapPage.cs index 850e398a93..a13a625d14 100644 --- a/samples/RenderDemo/Pages/WriteableBitmapPage.cs +++ b/samples/RenderDemo/Pages/WriteableBitmapPage.cs @@ -59,7 +59,7 @@ namespace RenderDemo.Pages color = new Color(fillAlpha, r, g, b); } - data[y * fb.Size.Width + x] = (int) color.ToUint32(); + data[y * fb.Size.Width + x] = (int) color.ToUInt32(); } } diff --git a/src/Avalonia.Base/Media/Color.cs b/src/Avalonia.Base/Media/Color.cs index 7b29ec640a..56a3b0d7a5 100644 --- a/src/Avalonia.Base/Media/Color.cs +++ b/src/Avalonia.Base/Media/Color.cs @@ -449,7 +449,7 @@ namespace Avalonia.Media /// public override string ToString() { - uint rgb = ToUint32(); + uint rgb = ToUInt32(); return KnownColors.GetKnownColorName(rgb) ?? $"#{rgb.ToString("x8", CultureInfo.InvariantCulture)}"; } @@ -459,11 +459,18 @@ namespace Avalonia.Media /// /// The integer representation of the color. /// - public uint ToUint32() + public uint ToUInt32() { return ((uint)A << 24) | ((uint)R << 16) | ((uint)G << 8) | (uint)B; } + /// + [Obsolete("Use Color.ToUInt32() instead.")] + public uint ToUint32() + { + return ToUInt32(); + } + /// /// Returns the HSL color model equivalent of this RGB color. /// diff --git a/src/Avalonia.Base/Media/GeometryDrawing.cs b/src/Avalonia.Base/Media/GeometryDrawing.cs index abfd2e33ac..75d7e44ab8 100644 --- a/src/Avalonia.Base/Media/GeometryDrawing.cs +++ b/src/Avalonia.Base/Media/GeometryDrawing.cs @@ -10,7 +10,7 @@ namespace Avalonia.Media public class GeometryDrawing : Drawing { // Adding the Pen's stroke thickness here could yield wrong results due to transforms. - private static readonly IPen s_boundsPen = new ImmutablePen(Colors.Black.ToUint32(), 0); + private static readonly IPen s_boundsPen = new ImmutablePen(Colors.Black.ToUInt32(), 0); /// /// Defines the property. diff --git a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs index 6c7b04dbfb..819e721b36 100644 --- a/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs +++ b/src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/AvaloniaXamlIlLanguageParseIntrinsics.cs @@ -155,7 +155,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions result = new XamlStaticOrTargetedReturnMethodCallNode(node, type.GetMethod( new FindMethodMethodSignature("FromUInt32", type, types.UInt) { IsStatic = true }), - new[] { new XamlConstantNode(node, types.UInt, color.ToUint32()) }); + new[] { new XamlConstantNode(node, types.UInt, color.ToUInt32()) }); return true; } @@ -242,7 +242,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions result = new XamlAstNewClrObjectNode(node, brushTypeRef, types.ImmutableSolidColorBrushConstructorColor, - new List { new XamlConstantNode(node, types.UInt, color.ToUint32()) }); + new List { new XamlConstantNode(node, types.UInt, color.ToUInt32()) }); return true; } diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs index 535b96420a..523b31e60a 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/DynamicResourceExtensionTests.cs @@ -34,7 +34,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions DelayedBinding.ApplyBindings(border); var brush = (ISolidColorBrush)border.Background; - Assert.Equal(0xff506070, brush.Color.ToUint32()); + Assert.Equal(0xff506070, brush.Color.ToUInt32()); } [Fact] @@ -81,7 +81,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions DelayedBinding.ApplyBindings(border); var brush = (ISolidColorBrush)border.Background; - Assert.Equal(0xff506070, brush.Color.ToUint32()); + Assert.Equal(0xff506070, brush.Color.ToUInt32()); } [Fact] @@ -109,7 +109,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions DelayedBinding.ApplyBindings(border); var brush = (ISolidColorBrush)border.Background; - Assert.Equal(0xff506070, brush.Color.ToUint32()); + Assert.Equal(0xff506070, brush.Color.ToUInt32()); } [Fact] @@ -141,7 +141,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions DelayedBinding.ApplyBindings(border); var brush = (ISolidColorBrush)border.Background; - Assert.Equal(0xff506070, brush.Color.ToUint32()); + Assert.Equal(0xff506070, brush.Color.ToUInt32()); } [Fact] @@ -161,7 +161,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions var border = window.FindControl("border"); var brush = (SolidColorBrush)border.Background; - Assert.Equal(0xff506070, brush.Color.ToUint32()); + Assert.Equal(0xff506070, brush.Color.ToUInt32()); } } @@ -187,7 +187,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions window.Show(); var brush = (SolidColorBrush)border.Background; - Assert.Equal(0xff506070, brush.Color.ToUint32()); + Assert.Equal(0xff506070, brush.Color.ToUInt32()); } } @@ -214,7 +214,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions var button = window.FindControl public IObservable Source { get; } - [Obsolete("Use Source property")] + [Obsolete("Use Source property"), EditorBrowsable(EditorBrowsableState.Never)] public IObservable Observable => Source; /// diff --git a/src/Avalonia.Base/Input/DataFormats.cs b/src/Avalonia.Base/Input/DataFormats.cs index 35d50e669a..f593ed205f 100644 --- a/src/Avalonia.Base/Input/DataFormats.cs +++ b/src/Avalonia.Base/Input/DataFormats.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; namespace Avalonia.Input { @@ -17,7 +18,7 @@ namespace Avalonia.Input /// /// Dataformat for one or more filenames /// - [Obsolete("Use DataFormats.Files, this format is supported only on desktop platforms.")] + [Obsolete("Use DataFormats.Files, this format is supported only on desktop platforms."), EditorBrowsable(EditorBrowsableState.Never)] public static readonly string FileNames = nameof(FileNames); } } diff --git a/src/Avalonia.Base/Input/DataObjectExtensions.cs b/src/Avalonia.Base/Input/DataObjectExtensions.cs index 6af531b0d8..d2e525cd68 100644 --- a/src/Avalonia.Base/Input/DataObjectExtensions.cs +++ b/src/Avalonia.Base/Input/DataObjectExtensions.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using Avalonia.Platform.Storage; @@ -25,7 +26,7 @@ namespace Avalonia.Input /// /// Collection of file names. If format isn't available, returns null. /// - [System.Obsolete("Use GetFiles, this method is supported only on desktop platforms.")] + [System.Obsolete("Use GetFiles, this method is supported only on desktop platforms."), EditorBrowsable(EditorBrowsableState.Never)] public static IEnumerable? GetFileNames(this IDataObject dataObject) { return (dataObject.Get(DataFormats.FileNames) as IEnumerable) diff --git a/src/Avalonia.Base/Media/Color.cs b/src/Avalonia.Base/Media/Color.cs index 56a3b0d7a5..50c2faacc0 100644 --- a/src/Avalonia.Base/Media/Color.cs +++ b/src/Avalonia.Base/Media/Color.cs @@ -6,6 +6,7 @@ // Licensed to The Avalonia Project under MIT License, courtesy of The .NET Foundation. using System; +using System.ComponentModel; using System.Globalization; #if !BUILDTASK using Avalonia.Animation.Animators; @@ -465,7 +466,7 @@ namespace Avalonia.Media } /// - [Obsolete("Use Color.ToUInt32() instead.")] + [Obsolete("Use Color.ToUInt32() instead."), EditorBrowsable(EditorBrowsableState.Never)] public uint ToUint32() { return ToUInt32(); diff --git a/src/Avalonia.Base/Media/DrawingContext.cs b/src/Avalonia.Base/Media/DrawingContext.cs index 18d6968168..3ab946a1db 100644 --- a/src/Avalonia.Base/Media/DrawingContext.cs +++ b/src/Avalonia.Base/Media/DrawingContext.cs @@ -5,6 +5,7 @@ using Avalonia.Rendering.SceneGraph; using Avalonia.Threading; using Avalonia.Utilities; using Avalonia.Media.Imaging; +using System.ComponentModel; namespace Avalonia.Media { @@ -417,11 +418,11 @@ namespace Avalonia.Media return new PushedState(this); } - [Obsolete("Use PushTransform")] + [Obsolete("Use PushTransform"), EditorBrowsable(EditorBrowsableState.Never)] public PushedState PushPreTransform(Matrix matrix) => PushTransform(matrix); - [Obsolete("Use PushTransform")] + [Obsolete("Use PushTransform"), EditorBrowsable(EditorBrowsableState.Never)] public PushedState PushPostTransform(Matrix matrix) => PushTransform(matrix); - [Obsolete("Use PushTransform")] + [Obsolete("Use PushTransform"), EditorBrowsable(EditorBrowsableState.Never)] public PushedState PushTransformContainer() => PushTransform(Matrix.Identity); diff --git a/src/Avalonia.Base/Threading/DispatcherPriority.cs b/src/Avalonia.Base/Threading/DispatcherPriority.cs index 3017b45dc7..a43dd8e4a2 100644 --- a/src/Avalonia.Base/Threading/DispatcherPriority.cs +++ b/src/Avalonia.Base/Threading/DispatcherPriority.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; namespace Avalonia.Threading { @@ -100,7 +101,7 @@ namespace Avalonia.Threading /// /// The job will be processed with the same priority as data binding. /// - [Obsolete("WPF compatibility")] public static readonly DispatcherPriority DataBind = new(Layout); + [Obsolete("WPF compatibility"), EditorBrowsable(EditorBrowsableState.Never)] public static readonly DispatcherPriority DataBind = new(Layout); /// /// The job will be processed with normal priority. diff --git a/src/Avalonia.Base/VisualTree/IVisualWithRoundRectClip.cs b/src/Avalonia.Base/VisualTree/IVisualWithRoundRectClip.cs index 9ace215d03..0079515a63 100644 --- a/src/Avalonia.Base/VisualTree/IVisualWithRoundRectClip.cs +++ b/src/Avalonia.Base/VisualTree/IVisualWithRoundRectClip.cs @@ -1,14 +1,15 @@ using System; +using System.ComponentModel; namespace Avalonia.VisualTree { - [Obsolete("Internal API, will be removed in future versions, you've been warned")] + [Obsolete("Internal API, will be removed in future versions, you've been warned"), EditorBrowsable(EditorBrowsableState.Never)] public interface IVisualWithRoundRectClip { /// /// Gets a value indicating the corner radius of control's clip bounds /// - [Obsolete("Internal API, will be removed in future versions, you've been warned")] + [Obsolete("Internal API, will be removed in future versions, you've been warned"), EditorBrowsable(EditorBrowsableState.Never)] CornerRadius ClipToBoundsRadius { get; } } diff --git a/src/Avalonia.Controls/ContextMenu.cs b/src/Avalonia.Controls/ContextMenu.cs index 63e28ea14d..97a8c6fe97 100644 --- a/src/Avalonia.Controls/ContextMenu.cs +++ b/src/Avalonia.Controls/ContextMenu.cs @@ -64,7 +64,7 @@ namespace Avalonia.Controls /// /// Defines the property. /// - [Obsolete("Use the Placement property instead.")] + [Obsolete("Use the Placement property instead."), EditorBrowsable(EditorBrowsableState.Never)] public static readonly StyledProperty PlacementModeProperty = PlacementProperty; /// @@ -157,7 +157,7 @@ namespace Avalonia.Controls } /// - [Obsolete("Use the Placement property instead.")] + [Obsolete("Use the Placement property instead."), EditorBrowsable(EditorBrowsableState.Never)] public PlacementMode PlacementMode { get => GetValue(PlacementProperty); diff --git a/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs b/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs index b2c138599e..d27479af18 100644 --- a/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs +++ b/src/Avalonia.Controls/Generators/ItemContainerGenerator.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; namespace Avalonia.Controls.Generators { @@ -131,10 +132,10 @@ namespace Avalonia.Controls.Generators /// public void ClearItemContainer(Control container) => _owner.ClearItemContainer(container); - [Obsolete("Use ItemsControl.ContainerFromIndex")] + [Obsolete("Use ItemsControl.ContainerFromIndex"), EditorBrowsable(EditorBrowsableState.Never)] public Control? ContainerFromIndex(int index) => _owner.ContainerFromIndex(index); - [Obsolete("Use ItemsControl.IndexFromContainer")] + [Obsolete("Use ItemsControl.IndexFromContainer"), EditorBrowsable(EditorBrowsableState.Never)] public int IndexFromContainer(Control container) => _owner.IndexFromContainer(container); } } diff --git a/src/Avalonia.Controls/Generators/TreeItemContainerGenerator.cs b/src/Avalonia.Controls/Generators/TreeItemContainerGenerator.cs index c1cae862a9..717dadb6ea 100644 --- a/src/Avalonia.Controls/Generators/TreeItemContainerGenerator.cs +++ b/src/Avalonia.Controls/Generators/TreeItemContainerGenerator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; namespace Avalonia.Controls.Generators { @@ -20,13 +21,13 @@ namespace Avalonia.Controls.Generators internal TreeContainerIndex(TreeView owner) => _owner = owner; - [Obsolete("Use TreeView.GetRealizedTreeContainers")] + [Obsolete("Use TreeView.GetRealizedTreeContainers"), EditorBrowsable(EditorBrowsableState.Never)] public IEnumerable Containers => _owner.GetRealizedTreeContainers(); - [Obsolete("Use TreeView.TreeContainerFromItem")] + [Obsolete("Use TreeView.TreeContainerFromItem"), EditorBrowsable(EditorBrowsableState.Never)] public Control? ContainerFromItem(object item) => _owner.TreeContainerFromItem(item); - [Obsolete("Use TreeView.TreeItemFromContainer")] + [Obsolete("Use TreeView.TreeItemFromContainer"), EditorBrowsable(EditorBrowsableState.Never)] public object? ItemFromContainer(Control container) => _owner.TreeItemFromContainer(container); } } diff --git a/src/Avalonia.Controls/ItemsControl.cs b/src/Avalonia.Controls/ItemsControl.cs index 1c62de9bed..4a0b3c367e 100644 --- a/src/Avalonia.Controls/ItemsControl.cs +++ b/src/Avalonia.Controls/ItemsControl.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; +using System.ComponentModel; using Avalonia.Automation.Peers; using Avalonia.Controls.Generators; using Avalonia.Controls.Metadata; @@ -626,7 +627,7 @@ namespace Avalonia.Controls /// TreeView to be able to create a . Can be /// removed in 12.0. /// - [Obsolete] + [Obsolete, EditorBrowsable(EditorBrowsableState.Never)] private protected virtual ItemContainerGenerator CreateItemContainerGenerator() { return new ItemContainerGenerator(this); diff --git a/src/Avalonia.Controls/Platform/Dialogs/ISystemDialogImpl.cs b/src/Avalonia.Controls/Platform/Dialogs/ISystemDialogImpl.cs index 996fff6775..a593caecaf 100644 --- a/src/Avalonia.Controls/Platform/Dialogs/ISystemDialogImpl.cs +++ b/src/Avalonia.Controls/Platform/Dialogs/ISystemDialogImpl.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Threading.Tasks; using Avalonia.Metadata; @@ -7,7 +8,7 @@ namespace Avalonia.Controls.Platform /// /// Defines a platform-specific system dialog implementation. /// - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] [Unstable] public interface ISystemDialogImpl { diff --git a/src/Avalonia.Controls/Platform/Dialogs/SystemDialogImpl.cs b/src/Avalonia.Controls/Platform/Dialogs/SystemDialogImpl.cs index 20bfb440e3..37e6272abd 100644 --- a/src/Avalonia.Controls/Platform/Dialogs/SystemDialogImpl.cs +++ b/src/Avalonia.Controls/Platform/Dialogs/SystemDialogImpl.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Avalonia.Platform.Storage; @@ -10,7 +11,7 @@ namespace Avalonia.Controls.Platform /// /// Defines a platform-specific system dialog implementation. /// - [Obsolete] + [Obsolete, EditorBrowsable(EditorBrowsableState.Never)] internal class SystemDialogImpl : ISystemDialogImpl { public async Task ShowFileDialogAsync(FileDialog dialog, Window parent) diff --git a/src/Avalonia.Controls/Platform/Screen.cs b/src/Avalonia.Controls/Platform/Screen.cs index 4898c5f912..fde90dc589 100644 --- a/src/Avalonia.Controls/Platform/Screen.cs +++ b/src/Avalonia.Controls/Platform/Screen.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; namespace Avalonia.Platform { @@ -17,7 +18,7 @@ namespace Avalonia.Platform public double Scaling { get; } /// - [Obsolete("Use the Scaling property instead.")] + [Obsolete("Use the Scaling property instead."), EditorBrowsable(EditorBrowsableState.Never)] public double PixelDensity => Scaling; /// @@ -43,7 +44,7 @@ namespace Avalonia.Platform public bool IsPrimary { get; } /// - [Obsolete("Use the IsPrimary property instead.")] + [Obsolete("Use the IsPrimary property instead."), EditorBrowsable(EditorBrowsableState.Never)] public bool Primary => IsPrimary; /// diff --git a/src/Avalonia.Controls/Primitives/Popup.cs b/src/Avalonia.Controls/Primitives/Popup.cs index eda794f33a..80b7841fc7 100644 --- a/src/Avalonia.Controls/Primitives/Popup.cs +++ b/src/Avalonia.Controls/Primitives/Popup.cs @@ -74,7 +74,7 @@ namespace Avalonia.Controls.Primitives /// /// Defines the property. /// - [Obsolete("Use the Placement property instead.")] + [Obsolete("Use the Placement property instead."), EditorBrowsable(EditorBrowsableState.Never)] public static readonly StyledProperty PlacementModeProperty = PlacementProperty; /// @@ -241,7 +241,7 @@ namespace Avalonia.Controls.Primitives } /// - [Obsolete("Use the Placement property instead.")] + [Obsolete("Use the Placement property instead."), EditorBrowsable(EditorBrowsableState.Never)] public PlacementMode PlacementMode { get => GetValue(PlacementProperty); diff --git a/src/Avalonia.Controls/Primitives/ToggleButton.cs b/src/Avalonia.Controls/Primitives/ToggleButton.cs index dfaf7bbc45..fa1bc76de4 100644 --- a/src/Avalonia.Controls/Primitives/ToggleButton.cs +++ b/src/Avalonia.Controls/Primitives/ToggleButton.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using Avalonia.Automation.Peers; using Avalonia.Controls.Metadata; using Avalonia.Data; @@ -28,7 +29,7 @@ namespace Avalonia.Controls.Primitives /// /// Defines the event. /// - [Obsolete("Use IsCheckedChangedEvent instead.")] + [Obsolete("Use IsCheckedChangedEvent instead."), EditorBrowsable(EditorBrowsableState.Never)] public static readonly RoutedEvent CheckedEvent = RoutedEvent.Register( nameof(Checked), @@ -37,7 +38,7 @@ namespace Avalonia.Controls.Primitives /// /// Defines the event. /// - [Obsolete("Use IsCheckedChangedEvent instead.")] + [Obsolete("Use IsCheckedChangedEvent instead."), EditorBrowsable(EditorBrowsableState.Never)] public static readonly RoutedEvent UncheckedEvent = RoutedEvent.Register( nameof(Unchecked), @@ -46,7 +47,7 @@ namespace Avalonia.Controls.Primitives /// /// Defines the event. /// - [Obsolete("Use IsCheckedChangedEvent instead.")] + [Obsolete("Use IsCheckedChangedEvent instead."), EditorBrowsable(EditorBrowsableState.Never)] public static readonly RoutedEvent IndeterminateEvent = RoutedEvent.Register( nameof(Indeterminate), @@ -72,7 +73,7 @@ namespace Avalonia.Controls.Primitives /// /// Raised when a is checked. /// - [Obsolete("Use IsCheckedChanged instead.")] + [Obsolete("Use IsCheckedChanged instead."), EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler? Checked { add => AddHandler(CheckedEvent, value); @@ -82,7 +83,7 @@ namespace Avalonia.Controls.Primitives /// /// Raised when a is unchecked. /// - [Obsolete("Use IsCheckedChanged instead.")] + [Obsolete("Use IsCheckedChanged instead."), EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler? Unchecked { add => AddHandler(UncheckedEvent, value); @@ -92,7 +93,7 @@ namespace Avalonia.Controls.Primitives /// /// Raised when a is neither checked nor unchecked. /// - [Obsolete("Use IsCheckedChanged instead.")] + [Obsolete("Use IsCheckedChanged instead."), EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler? Indeterminate { add => AddHandler(IndeterminateEvent, value); @@ -168,7 +169,7 @@ namespace Avalonia.Controls.Primitives /// Called when becomes true. /// /// Event arguments for the routed event that is raised by the default implementation of this method. - [Obsolete("Use OnIsCheckedChanged instead.")] + [Obsolete("Use OnIsCheckedChanged instead."), EditorBrowsable(EditorBrowsableState.Never)] protected virtual void OnChecked(RoutedEventArgs e) { RaiseEvent(e); @@ -178,7 +179,7 @@ namespace Avalonia.Controls.Primitives /// Called when becomes false. /// /// Event arguments for the routed event that is raised by the default implementation of this method. - [Obsolete("Use OnIsCheckedChanged instead.")] + [Obsolete("Use OnIsCheckedChanged instead."), EditorBrowsable(EditorBrowsableState.Never)] protected virtual void OnUnchecked(RoutedEventArgs e) { RaiseEvent(e); @@ -188,7 +189,7 @@ namespace Avalonia.Controls.Primitives /// Called when becomes null. /// /// Event arguments for the routed event that is raised by the default implementation of this method. - [Obsolete("Use OnIsCheckedChanged instead.")] + [Obsolete("Use OnIsCheckedChanged instead."), EditorBrowsable(EditorBrowsableState.Never)] protected virtual void OnIndeterminate(RoutedEventArgs e) { RaiseEvent(e); diff --git a/src/Avalonia.Controls/Screens.cs b/src/Avalonia.Controls/Screens.cs index 60d5358c49..c65aaafa4b 100644 --- a/src/Avalonia.Controls/Screens.cs +++ b/src/Avalonia.Controls/Screens.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using Avalonia.Platform; @@ -68,7 +69,7 @@ namespace Avalonia.Controls /// /// The window impl for which to retrieve the Screen. /// The . - [Obsolete("Use ScreenFromWindow(WindowBase) overload.")] + [Obsolete("Use ScreenFromWindow(WindowBase) overload."), EditorBrowsable(EditorBrowsableState.Never)] public Screen? ScreenFromWindow(IWindowBaseImpl window) { return _iScreenImpl.ScreenFromWindow(window); diff --git a/src/Avalonia.Controls/SystemDialog.cs b/src/Avalonia.Controls/SystemDialog.cs index d2b893df37..8d4dab11d7 100644 --- a/src/Avalonia.Controls/SystemDialog.cs +++ b/src/Avalonia.Controls/SystemDialog.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Avalonia.Controls.Platform; @@ -11,7 +12,7 @@ namespace Avalonia.Controls /// /// Base class for system file dialogs. /// - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] public abstract class FileDialog : FileSystemDialog { /// @@ -29,7 +30,7 @@ namespace Avalonia.Controls /// /// Base class for system file and directory dialogs. /// - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] public abstract class FileSystemDialog : SystemDialog { /// @@ -42,7 +43,7 @@ namespace Avalonia.Controls /// /// Represents a system dialog that prompts the user to select a location for saving a file. /// - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] public class SaveFileDialog : FileDialog { /// @@ -91,7 +92,7 @@ namespace Avalonia.Controls /// /// Represents a system dialog that allows the user to select one or more files to open. /// - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] public class OpenFileDialog : FileDialog { /// @@ -132,7 +133,7 @@ namespace Avalonia.Controls /// /// Represents a system dialog that allows the user to select a directory. /// - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] public class OpenFolderDialog : FileSystemDialog { /// @@ -167,7 +168,7 @@ namespace Avalonia.Controls /// /// Base class for system dialogs. /// - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] public abstract class SystemDialog { static SystemDialog() @@ -188,7 +189,7 @@ namespace Avalonia.Controls /// /// Represents a filter in an or an . /// - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] public class FileDialogFilter { /// diff --git a/src/Avalonia.Controls/TreeView.cs b/src/Avalonia.Controls/TreeView.cs index e3a9a05951..5122b4aebd 100644 --- a/src/Avalonia.Controls/TreeView.cs +++ b/src/Avalonia.Controls/TreeView.cs @@ -3,6 +3,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Linq; using Avalonia.Collections; @@ -715,7 +716,7 @@ namespace Avalonia.Controls } } - [Obsolete] + [Obsolete, EditorBrowsable(EditorBrowsableState.Never)] private protected override ItemContainerGenerator CreateItemContainerGenerator() { return new TreeItemContainerGenerator(this); diff --git a/src/Avalonia.Dialogs/ManagedFileDialogExtensions.cs b/src/Avalonia.Dialogs/ManagedFileDialogExtensions.cs index e9a75ab46a..86c0bfc588 100644 --- a/src/Avalonia.Dialogs/ManagedFileDialogExtensions.cs +++ b/src/Avalonia.Dialogs/ManagedFileDialogExtensions.cs @@ -1,6 +1,7 @@ #nullable enable using System; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using Avalonia.Controls; @@ -39,11 +40,11 @@ namespace Avalonia.Dialogs return builder; } - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] public static Task ShowManagedAsync(this OpenFileDialog dialog, Window parent, ManagedFileDialogOptions? options = null) => ShowManagedAsync(dialog, parent, options); - [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API")] + [Obsolete("Use Window.StorageProvider API or TopLevel.StorageProvider API"), EditorBrowsable(EditorBrowsableState.Never)] public static async Task ShowManagedAsync(this OpenFileDialog dialog, Window parent, ManagedFileDialogOptions? options = null) where TWindow : Window, new() { diff --git a/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs b/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs index 7e73397743..83bf795b03 100644 --- a/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs +++ b/src/Avalonia.OpenGL/Controls/OpenGlControlBase.cs @@ -8,6 +8,8 @@ using Avalonia.Rendering; using Avalonia.Rendering.Composition; using Avalonia.VisualTree; using Avalonia.Platform; +using System.ComponentModel; + namespace Avalonia.OpenGL.Controls { public abstract class OpenGlControlBase : Control @@ -217,7 +219,7 @@ namespace Avalonia.OpenGL.Controls return true; } - [Obsolete("Use RequestNextFrameRendering()")] + [Obsolete("Use RequestNextFrameRendering()"), EditorBrowsable(EditorBrowsableState.Never)] // ReSharper disable once MemberCanBeProtected.Global public new void InvalidateVisual() => RequestNextFrameRendering(); From f0ea1f11161a6c390b7c5173069701b78af02302 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Wed, 3 May 2023 14:23:34 +0600 Subject: [PATCH 76/80] Fixed some potential threading issues --- .../Threading/DispatcherFrame.cs | 57 ++++++++++++------- .../Platform/ManagedDispatcherImpl.cs | 6 ++ 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/Avalonia.Base/Threading/DispatcherFrame.cs b/src/Avalonia.Base/Threading/DispatcherFrame.cs index 1f8974dfa3..e826432475 100644 --- a/src/Avalonia.Base/Threading/DispatcherFrame.cs +++ b/src/Avalonia.Base/Threading/DispatcherFrame.cs @@ -91,31 +91,44 @@ public class DispatcherFrame internal void Run(IControlledDispatcherImpl impl) { - // Since the actual platform run loop is controlled by a Cancellation token, we are restarting - // it if frame still needs to run - while (Continue) - RunCore(impl); - } - - private void RunCore(IControlledDispatcherImpl impl) - { - if (_isRunning) - throw new InvalidOperationException("This frame is already running"); - _isRunning = true; - try - { - _cancellationTokenSource = new CancellationTokenSource(); - // Wake up the dispatcher in case it has pending jobs - Dispatcher.RequestProcessing(); - impl.RunLoop(_cancellationTokenSource.Token); - } - finally + Dispatcher.VerifyAccess(); + + // Since the actual platform run loop is controlled by a Cancellation token, we have an + // outer loop that restarts the platform one in case Continue was set to true after being set to false + while (true) { - _isRunning = false; - _cancellationTokenSource?.Cancel(); - _cancellationTokenSource = null; + // Take the instance lock since `Continue` is changed from one too + lock (Dispatcher.InstanceLock) + { + if (!Continue) + return; + + if (_isRunning) + throw new InvalidOperationException("This frame is already running"); + + _cancellationTokenSource = new CancellationTokenSource(); + _isRunning = true; + } + + try + { + // Wake up the dispatcher in case it has pending jobs + Dispatcher.RequestProcessing(); + impl.RunLoop(_cancellationTokenSource.Token); + } + finally + { + lock (Dispatcher.InstanceLock) + { + _isRunning = false; + _cancellationTokenSource?.Cancel(); + _cancellationTokenSource?.Dispose(); + _cancellationTokenSource = null; + } + } } } + internal void MaybeExitOnDispatcherRequest() { diff --git a/src/Avalonia.Controls/Platform/ManagedDispatcherImpl.cs b/src/Avalonia.Controls/Platform/ManagedDispatcherImpl.cs index 20aa91c83e..fdc098777a 100644 --- a/src/Avalonia.Controls/Platform/ManagedDispatcherImpl.cs +++ b/src/Avalonia.Controls/Platform/ManagedDispatcherImpl.cs @@ -58,6 +58,10 @@ public class ManagedDispatcherImpl : IControlledDispatcherImpl public void RunLoop(CancellationToken token) { + CancellationTokenRegistration registration = default; + if (token.CanBeCanceled) + registration = token.Register(() => _wakeup.Set()); + while (!token.IsCancellationRequested) { bool signaled; @@ -105,5 +109,7 @@ public class ManagedDispatcherImpl : IControlledDispatcherImpl else _wakeup.WaitOne(); } + + registration.Dispose(); } } \ No newline at end of file From 2f7c518f1e12ac8bc28c261144db50683dbf187d Mon Sep 17 00:00:00 2001 From: Mike James Date: Wed, 3 May 2023 10:25:35 +0200 Subject: [PATCH 77/80] Update readme.md Refreshing the readme to match our current branding. --- readme.md | 65 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/readme.md b/readme.md index c8135080fe..339cce9ee1 100644 --- a/readme.md +++ b/readme.md @@ -1,26 +1,44 @@ -[![GH_Banner](https://user-images.githubusercontent.com/552074/218457976-92e76834-9e22-4e35-acfa-aa50281bc0f9.png)](https://avaloniaui.net/xpf) +![StarBanner3](https://user-images.githubusercontent.com/552074/235864283-691ac648-5113-4b5c-87e8-bed9ba192927.png) + +![Header](https://user-images.githubusercontent.com/552074/235865745-2a8e7274-4f66-4f77-8f05-feeb76e7d478.png) [![Telegram](https://raw.githubusercontent.com/Patrolavia/telegram-badge/master/chat.svg)](https://t.me/Avalonia) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/AvaloniaUI/Avalonia?utm_campaign=pr-badge&utm_content=badge&utm_medium=badge&utm_source=badge) [![Discord](https://img.shields.io/badge/discord-join%20chat-46BC99)]( https://aka.ms/dotnet-discord) [![Build Status](https://dev.azure.com/AvaloniaUI/AvaloniaUI/_apis/build/status/AvaloniaUI.Avalonia)](https://dev.azure.com/AvaloniaUI/AvaloniaUI/_build/latest?definitionId=4) [![Backers on Open Collective](https://opencollective.com/Avalonia/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/Avalonia/sponsors/badge.svg)](#sponsors) ![License](https://img.shields.io/github/license/avaloniaui/avalonia.svg)
[![NuGet](https://img.shields.io/nuget/v/Avalonia.svg)](https://www.nuget.org/packages/Avalonia) [![downloads](https://img.shields.io/nuget/dt/avalonia)](https://www.nuget.org/packages/Avalonia) ![Size](https://img.shields.io/github/repo-size/avaloniaui/avalonia.svg) -# ⚠️ **v11 Update - Pausing community contributions** - -for more information see [this](https://github.com/AvaloniaUI/Avalonia/discussions/10599) discussion. +⚠️ **v11 Update - [Pausing community contributions](https://github.com/AvaloniaUI/Avalonia/discussions/10599)** ## 📖 About -Avalonia is a cross-platform UI framework for dotnet, providing a flexible styling system and supporting a wide range of Operating Systems such as Windows, Linux, macOS. Avalonia is mature and production ready. We also have in beta release support for iOS, Android and in early stages support for browser via WASM. +[Avalonia](https://avaloniaui.net) is a cross-platform UI framework for dotnet, providing a flexible styling system and supporting a wide range of platforms such as Windows, macOS, Linux, iOS, Android and WebAssembly. Avalonia is mature and production ready and is used by companies, including [Schneider Electric](https://avaloniaui.net/showcase#se), [Unity](https://avaloniaui.net/showcase#unity), [JetBrains](https://avaloniaui.net/showcase#rider) and [Github](https://avaloniaui.net/showcase#github). + +Considered by many to be the spiritual successor to WPF, Avalonia UI provides a familiar, modern development experience for XAML developers creating cross-platform applications. While Avalonia UI is [similar to WPF](https://docs.avaloniaui.net/misc/wpf), it isn't a 1:1 copy, and you'll find plenty of improvements. + +For those seeking a cross-platform WPF, we have created [Avalonia XPF](https://avaloniaui.net/xpf), enabling WPF applications to run on macOS and Linux with little to no code changes. Avalonia XPF is a commercial product and is licensed per-app, per-platform. + +#### Roadmap +To see the status of some of our features, please see our [Roadmap](https://github.com/AvaloniaUI/Avalonia/issues/2239). -![image](https://user-images.githubusercontent.com/4672627/152126443-932966cf-57e7-4e77-9be6-62463a66b9f8.png) +#### Breaking Changes +You can also see what [breaking changes](https://github.com/AvaloniaUI/Avalonia/issues/3538) we have planned and what our [past breaking changes](https://github.com/AvaloniaUI/Avalonia/wiki/Breaking-Changes) have been. -To see the status of some of our features, please see our [Roadmap](https://github.com/AvaloniaUI/Avalonia/issues/2239). You can also see what [breaking changes](https://github.com/AvaloniaUI/Avalonia/issues/3538) we have planned and what our [past breaking changes](https://github.com/AvaloniaUI/Avalonia/wiki/Breaking-Changes) have been. [Awesome Avalonia](https://github.com/AvaloniaCommunity/awesome-avalonia) is community-curated list of awesome Avalonia UI tools, libraries, projects and resources. Go and see what people are building with Avalonia! +#### Awesome Avalonia +[Awesome Avalonia](https://github.com/AvaloniaCommunity/awesome-avalonia) is community-curated list of awesome Avalonia UI tools, libraries, projects and resources. Go and see what people are building with Avalonia! ## 🚀 Getting Started +See our [Get Started](https://avaloniaui.net/GettingStarted) guide to begin developing apps with Avalonia UI. + +### Visual Studio The Avalonia [Visual Studio Extension](https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaforVisualStudio) contains project and control templates that will help you get started, or you can use the .NET Core CLI. For a starter guide see our [documentation](https://docs.avaloniaui.net/docs/getting-started). +### JetBrains Rider +[JetBrains Rider](https://www.jetbrains.com/rider/whatsnew/?mkt_tok=eyJpIjoiTURBNU1HSmhNV0kwTUdFMiIsInQiOiJtNnU2VEc1TlNLa1ZRVkROYmdZYVpYREJsaU1qdUhmS3dxSzRHczdYWHl0RVlTNDMwSFwvNUs3VENTNVM0bVcyNFdaRmVYZzVWTTF1N3VrQWNGTkJreEhlam1hMlB4UVVWcHBGM1dNOUxoXC95YnRQdGgyUXl1YmZCM3h3d3BVWWdBIn0%3D#avalonia-support) now has official support for Avalonia. + +Code completion, inspections and refactorings are supported out of the box, for XAML previewer add `https://plugins.jetbrains.com/plugins/dev/14839` to plugin repositories and install [AvaloniaRider](https://github.com/ForNeVeR/AvaloniaRider) plugin. + +### Avalonia Packages Avalonia is delivered via NuGet package manager. You can find the packages here: https://www.nuget.org/packages/Avalonia/ Use these commands in the Package Manager console to install Avalonia manually: @@ -30,31 +48,25 @@ Install-Package Avalonia.Desktop ``` ## Showcase +[![Showcase_Banner](https://user-images.githubusercontent.com/552074/235865504-f9acaf42-ea2d-456a-ab52-547c45614bd5.png)](https://avaloniaui.net/showcase) -Examples of UIs built with Avalonia - -([Lunacy](https://icons8.com/lunacy)) - -![image](https://user-images.githubusercontent.com/4672627/152325740-261c27a3-e6f0-4662-bff7-4796d4940e04.png) -([PlasticSCM](https://www.plasticscm.com/)) -![image](https://user-images.githubusercontent.com/4672627/152326453-14944c4d-33da-4d50-a268-b87f80927adb.png) -([WasabiWallet](https://www.wasabiwallet.io/)) - - -## JetBrains Rider - -[JetBrains Rider](https://www.jetbrains.com/rider/whatsnew/?mkt_tok=eyJpIjoiTURBNU1HSmhNV0kwTUdFMiIsInQiOiJtNnU2VEc1TlNLa1ZRVkROYmdZYVpYREJsaU1qdUhmS3dxSzRHczdYWHl0RVlTNDMwSFwvNUs3VENTNVM0bVcyNFdaRmVYZzVWTTF1N3VrQWNGTkJreEhlam1hMlB4UVVWcHBGM1dNOUxoXC95YnRQdGgyUXl1YmZCM3h3d3BVWWdBIn0%3D#avalonia-support) now has official support for Avalonia. - -Code completion, inspections and refactorings are supported out of the box, for XAML previewer add `https://plugins.jetbrains.com/plugins/dev/14839` to plugin repositories and install [AvaloniaRider](https://github.com/ForNeVeR/AvaloniaRider) plugin. +See what others have built with Avalonia UI on our [Showcase](https://avaloniaui.net/Showcase). We welcome submissions! ## Bleeding Edge Builds We also have a [nightly build](https://github.com/AvaloniaUI/Avalonia/wiki/Using-nightly-build-feed) which tracks the current state of master. Although these packages are less stable than the release on NuGet.org, you'll get all the latest features and bugfixes right away and many of our users actually prefer this feed! -## Documentation +## Learning -Documentation can be found at https://docs.avaloniaui.net. We also have a [tutorial](https://docs.avaloniaui.net/docs/getting-started/programming-with-avalonia) over there for newcomers. +### Documentation +Documentation can be found at https://docs.avaloniaui.net. + +### Tutorials +We also have a [tutorial](https://docs.avaloniaui.net/docs/getting-started/programming-with-avalonia) over there for newcomers. + +### Samples +We have a [range of samples](https://github.com/AvaloniaUI/Avalonia.Samples) to help you get started. ## Building and Using @@ -116,3 +128,8 @@ We have a range of [support plans available](https://avaloniaui.net/support) for ## .NET Foundation This project is supported by the [.NET Foundation](https://dotnetfoundation.org). + +## Avalonia XPF +Unleash the full potential of your existing WPF apps with our cross-platform UI framework, enabling WPF apps to run on macOS and Linux without requiring expensive and risky rewrites. + +[![GH_Banner](https://user-images.githubusercontent.com/552074/218457976-92e76834-9e22-4e35-acfa-aa50281bc0f9.png)](https://avaloniaui.net/xpf) From 015768c5bd29932372a5007a087e2d4f11eaa238 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Wed, 3 May 2023 14:26:02 +0600 Subject: [PATCH 78/80] Make sure that Dispatcher.InvokeAsync unwraps tasks and that correct overload is being chosen --- .../Threading/Dispatcher.Invoke.cs | 42 +++++++++++++++--- .../DispatcherTests.cs | 44 +++++++++++++++++++ 2 files changed, 80 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Base/Threading/Dispatcher.Invoke.cs b/src/Avalonia.Base/Threading/Dispatcher.Invoke.cs index 699186868a..bb1663eac0 100644 --- a/src/Avalonia.Base/Threading/Dispatcher.Invoke.cs +++ b/src/Avalonia.Base/Threading/Dispatcher.Invoke.cs @@ -248,11 +248,11 @@ public partial class Dispatcher /// An operation representing the queued delegate to be invoked. /// /// - /// Note that the default priority is DispatcherPriority.Normal. + /// Note that the default priority is DispatcherPriority.Default. /// public DispatcherOperation InvokeAsync(Action callback) { - return InvokeAsync(callback, DispatcherPriority.Normal, CancellationToken.None); + return InvokeAsync(callback, default, CancellationToken.None); } /// @@ -326,11 +326,11 @@ public partial class Dispatcher /// An operation representing the queued delegate to be invoked. /// /// - /// Note that the default priority is DispatcherPriority.Normal. + /// Note that the default priority is DispatcherPriority.Default. /// public DispatcherOperation InvokeAsync(Func callback) { - return InvokeAsync(callback, DispatcherPriority.Normal, CancellationToken.None); + return InvokeAsync(callback, DispatcherPriority.Default, CancellationToken.None); } /// @@ -541,6 +541,18 @@ public partial class Dispatcher InvokeAsyncImpl(new DispatcherOperation(this, priority, action, true), CancellationToken.None); } + /// + /// Executes the specified Func<Task> asynchronously on the + /// thread that the Dispatcher was created on + /// + /// + /// A Func<Task> delegate to invoke through the dispatcher. + /// + /// + /// An task that completes after the task returned from callback finishes. + /// + public Task InvokeAsync(Func callback) => InvokeAsync(callback, DispatcherPriority.Default); + /// /// Executes the specified Func<Task> asynchronously on the /// thread that the Dispatcher was created on @@ -556,11 +568,29 @@ public partial class Dispatcher /// /// An task that completes after the task returned from callback finishes /// - public Task InvokeAsync(Func callback, DispatcherPriority priority = default) + public Task InvokeAsync(Func callback, DispatcherPriority priority) { _ = callback ?? throw new ArgumentNullException(nameof(callback)); return InvokeAsync(callback, priority).GetTask().Unwrap(); } + + /// + /// Executes the specified Func<Task<TResult>> asynchronously on the + /// thread that the Dispatcher was created on + /// + /// + /// A Func<Task<TResult>> delegate to invoke through the dispatcher. + /// + /// + /// The priority that determines in what order the specified + /// callback is invoked relative to the other pending operations + /// in the Dispatcher. + /// + /// + /// An task that completes after the task returned from callback finishes + /// + public Task InvokeAsync(Func> action) => + InvokeAsync(action, DispatcherPriority.Default); /// /// Executes the specified Func<Task<TResult>> asynchronously on the @@ -577,7 +607,7 @@ public partial class Dispatcher /// /// An task that completes after the task returned from callback finishes /// - public Task InvokeAsync(Func> action, DispatcherPriority priority = default) + public Task InvokeAsync(Func> action, DispatcherPriority priority) { _ = action ?? throw new ArgumentNullException(nameof(action)); return InvokeAsync>(action, priority).GetTask().Unwrap(); diff --git a/tests/Avalonia.Base.UnitTests/DispatcherTests.cs b/tests/Avalonia.Base.UnitTests/DispatcherTests.cs index 9ba3f3980d..7b401918ce 100644 --- a/tests/Avalonia.Base.UnitTests/DispatcherTests.cs +++ b/tests/Avalonia.Base.UnitTests/DispatcherTests.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading; +using System.Threading.Tasks; +using Avalonia.Controls.Platform; using Avalonia.Threading; using Avalonia.Utilities; using Xunit; @@ -458,4 +460,46 @@ public class DispatcherTests } } + [Fact] + public void DispatcherInvokeAsyncUnwrapsTasks() + { + int asyncMethodStage = 0; + + async Task AsyncMethod() + { + asyncMethodStage = 1; + await Task.Delay(200); + asyncMethodStage = 2; + } + + async Task AsyncMethodWithResult() + { + await Task.Delay(100); + return 1; + } + + async Task Test() + { + await Dispatcher.UIThread.InvokeAsync(AsyncMethod); + Assert.Equal(2, asyncMethodStage); + Assert.Equal(1, await Dispatcher.UIThread.InvokeAsync(AsyncMethodWithResult)); + asyncMethodStage = 0; + + await Dispatcher.UIThread.InvokeAsync(AsyncMethod, DispatcherPriority.Default); + Assert.Equal(2, asyncMethodStage); + Assert.Equal(1, await Dispatcher.UIThread.InvokeAsync(AsyncMethodWithResult, DispatcherPriority.Default)); + + Dispatcher.UIThread.ExitAllFrames(); + } + + using (new DispatcherServices(new ManagedDispatcherImpl(null))) + { + var t = Test(); + var cts = new CancellationTokenSource(); + Task.Delay(3000).ContinueWith(_ => cts.Cancel()); + Dispatcher.UIThread.MainLoop(cts.Token); + Assert.True(t.IsCompletedSuccessfully); + t.GetAwaiter().GetResult(); + } + } } \ No newline at end of file From 1604dd701c7769791a3e7dc9931b7c8bdf6d817f Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 3 May 2023 13:19:17 +0200 Subject: [PATCH 79/80] The default cursor is called "default" and not "pointer" --- src/Browser/Avalonia.Browser/webapp/modules/avalonia/input.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Browser/Avalonia.Browser/webapp/modules/avalonia/input.ts b/src/Browser/Avalonia.Browser/webapp/modules/avalonia/input.ts index bbc59aba1c..77166e6f21 100644 --- a/src/Browser/Avalonia.Browser/webapp/modules/avalonia/input.ts +++ b/src/Browser/Avalonia.Browser/webapp/modules/avalonia/input.ts @@ -266,7 +266,7 @@ export class InputHelper { } public static setCursor(inputElement: HTMLInputElement, kind: string) { - if (kind === "pointer") { + if (kind === "default") { inputElement.style.removeProperty("cursor"); } else { inputElement.style.cursor = kind; From f956aa10e7005ee3c5dd9b9a52ce8221b672cc0b Mon Sep 17 00:00:00 2001 From: Mike James Date: Wed, 3 May 2023 16:28:01 +0200 Subject: [PATCH 80/80] Update readme.md Tweaked images to look slightly better in dark mode. --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 339cce9ee1..6dd556bd0d 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,4 @@ -![StarBanner3](https://user-images.githubusercontent.com/552074/235864283-691ac648-5113-4b5c-87e8-bed9ba192927.png) - +![Star our repo to show support](https://user-images.githubusercontent.com/552074/235945895-1b896994-a0b6-4e7c-a522-c5688c4ec1b9.png) ![Header](https://user-images.githubusercontent.com/552074/235865745-2a8e7274-4f66-4f77-8f05-feeb76e7d478.png) [![Telegram](https://raw.githubusercontent.com/Patrolavia/telegram-badge/master/chat.svg)](https://t.me/Avalonia) @@ -48,7 +47,8 @@ Install-Package Avalonia.Desktop ``` ## Showcase -[![Showcase_Banner](https://user-images.githubusercontent.com/552074/235865504-f9acaf42-ea2d-456a-ab52-547c45614bd5.png)](https://avaloniaui.net/showcase) +[![Showcase_Banner](https://user-images.githubusercontent.com/552074/235946124-bf6fda52-0c9f-4730-868b-0de957e5b97b.png)](https://avaloniaui.net/showcase) + See what others have built with Avalonia UI on our [Showcase](https://avaloniaui.net/Showcase). We welcome submissions!