Browse Source

Fix AVP1012 warnings in Avalonia.Base (#13717)

Julien Lebosquain 1 year ago
parent
commit
18a3c43e44

+ 1 - 1
src/Avalonia.Base/Input/PinchEventArgs.cs

@@ -24,7 +24,7 @@ namespace Avalonia.Input
 
         /// <summary>
         /// Gets the angle of the pinch gesture, in degrees.
-        /// <summary>
+        /// </summary>
         /// <remarks>
         /// A pinch gesture is the movement of two pressed points closer together. This property is the measured angle of the line between those two points. Remember zero degrees is a line pointing up.
         /// </remarks>

+ 2 - 0
src/Avalonia.Base/Media/PolyLineSegment.cs

@@ -39,6 +39,8 @@ namespace Avalonia.Media
         /// Initializes a new instance of the <see cref="PolyLineSegment"/> class.
         /// </summary>
         /// <param name="points">The points.</param>
+        [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1012",
+            Justification = "Collection properties shouldn't be set with SetCurrentValue.")]
         public PolyLineSegment(IEnumerable<Point> points)
         {
             Points = new Points(points);

+ 3 - 3
src/Avalonia.Controls/TabItem.cs

@@ -72,14 +72,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);
                     }
                 }
             }
@@ -87,7 +87,7 @@ namespace Avalonia.Controls
             {
                 if (Header == obj.OldValue)
                 {
-                    Header = obj.NewValue;
+                    SetCurrentValue(HeaderProperty, obj.NewValue);
                 }
             }
         }

+ 26 - 1
tests/Avalonia.Controls.UnitTests/TabControlTests.cs

@@ -2,7 +2,6 @@ using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
-using Avalonia.Collections;
 using Avalonia.Controls.Presenters;
 using Avalonia.Controls.Primitives;
 using Avalonia.Controls.Selection;
@@ -547,6 +546,32 @@ namespace Avalonia.Controls.UnitTests
             Assert.Same(item, root.FocusManager.GetFocusedElement());
         }
 
+        [Fact]
+        public void TabItem_Header_Should_Be_Settable_By_Style_When_DataContext_Is_Set()
+        {
+            var tabItem = new TabItem
+            {
+                DataContext = "Some DataContext"
+            };
+
+            _ = new TestRoot
+            {
+                Styles =
+                {
+                    new Style(x => x.OfType<TabItem>())
+                    {
+                        Setters =
+                        {
+                            new Setter(HeaderedContentControl.HeaderProperty, "Header from style")
+                        }
+                    }
+                },
+                Child = tabItem
+            };
+
+            Assert.Equal("Header from style", tabItem.Header);
+        }
+
         private static IControlTemplate TabControlTemplate()
         {
             return new FuncControlTemplate<TabControl>((parent, scope) =>