Browse Source

Merge remote-tracking branch 'origin/master' into fixes/4781-treeview-setting-bound-selected-item-null

Dan Walmsley 5 năm trước cách đây
mục cha
commit
cadbb7cc04

+ 1 - 1
src/Avalonia.Animation/KeySplineTypeConverter.cs

@@ -19,7 +19,7 @@ namespace Avalonia.Animation
 
         public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
         {
-            return KeySpline.Parse((string)value, culture);
+            return KeySpline.Parse((string)value, CultureInfo.InvariantCulture);
         }
     }
 }

+ 22 - 2
src/Avalonia.Controls.DataGrid/DataGrid.cs

@@ -31,7 +31,7 @@ namespace Avalonia.Controls
     /// <summary>
     /// Displays data in a customizable grid.
     /// </summary>
-    [PseudoClasses(":invalid")]
+    [PseudoClasses(":invalid", ":empty-rows", ":empty-columns")]
     public partial class DataGrid : TemplatedControl
     {
         private const string DATAGRID_elementRowsPresenterName = "PART_RowsPresenter";
@@ -711,6 +711,7 @@ namespace Avalonia.Controls
 
             DisplayData = new DataGridDisplayData(this);
             ColumnsInternal = CreateColumnsInstance();
+            ColumnsInternal.CollectionChanged += ColumnsInternal_CollectionChanged;
 
             RowHeightEstimate = DATAGRID_defaultRowHeight;
             RowDetailsHeightEstimate = 0;
@@ -727,6 +728,8 @@ namespace Avalonia.Controls
             CurrentCellCoordinates = new DataGridCellCoordinates(-1, -1);
 
             RowGroupHeaderHeightEstimate = DATAGRID_defaultRowHeight;
+
+            UpdatePseudoClasses();
         }
 
         private void SetValueNoCallback<T>(AvaloniaProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)
@@ -851,9 +854,27 @@ namespace Avalonia.Controls
                 // can be set when the DataGrid is not part of the visual tree
                 _measured = false;
                 InvalidateMeasure();
+
+                UpdatePseudoClasses();
             }
         }
 
+        private void ColumnsInternal_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
+        {
+            if (e.Action == NotifyCollectionChangedAction.Add
+                || e.Action == NotifyCollectionChangedAction.Remove
+                || e.Action == NotifyCollectionChangedAction.Reset)
+            {
+                UpdatePseudoClasses();
+            }
+        }
+
+        internal void UpdatePseudoClasses()
+        {
+            PseudoClasses.Set(":empty-columns", !ColumnsInternal.GetVisibleColumns().Any());
+            PseudoClasses.Set(":empty-rows", !DataConnection.Any());
+        }
+
         private void OnSelectedIndexChanged(AvaloniaPropertyChangedEventArgs e)
         {
             if (!_areHandlersSuspended)
@@ -1348,7 +1369,6 @@ namespace Avalonia.Controls
         internal DataGridColumnCollection ColumnsInternal
         {
             get;
-            private set;
         }
 
         internal int AnchorSlot

+ 21 - 18
src/Avalonia.Controls.DataGrid/DataGridDataConnection.cs

@@ -77,24 +77,7 @@ namespace Avalonia.Controls
             private set;
         }
 
-        public int Count
-        {
-            get
-            {
-                IList list = List;
-                if (list != null)
-                {
-                    return list.Count;
-                }
-
-                if(DataSource is DataGridCollectionView cv)
-                {
-                    return cv.Count;
-                }
-
-                return DataSource?.Cast<object>().Count() ?? 0;
-            }
-        }
+        public int Count => GetCount(true);
 
         public bool DataIsPrimitive
         {
@@ -210,6 +193,24 @@ namespace Avalonia.Controls
             }
         }
 
+        internal bool Any()
+        {
+            return GetCount(false) > 0;
+        }
+
+        /// <param name="allowSlow">When "allowSlow" is false, method will not use Linq.Count() method and will return 0 or 1 instead.</param>
+        private int GetCount(bool allowSlow)
+        {
+            return DataSource switch
+            {
+                ICollection collection => collection.Count,
+                DataGridCollectionView cv => cv.Count,
+                IEnumerable enumerable when allowSlow => enumerable.Cast<object>().Count(),
+                IEnumerable enumerable when !allowSlow => enumerable.Cast<object>().Any() ? 1 : 0,
+                _ => 0
+            };
+        }
+
         /// <summary>
         /// Puts the entity into editing mode if possible
         /// </summary>
@@ -675,6 +676,8 @@ namespace Avalonia.Controls
                     }
                     break;
             }
+
+            _owner.UpdatePseudoClasses();
         }
 
         private void UpdateDataProperties()

+ 12 - 9
src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml

@@ -588,18 +588,11 @@
             <!--<DataGridColumnHeader Name="PART_TopRightCornerHeader"
                                   Grid.Column="2"
                                   Template="{StaticResource TopRightHeaderTemplate}" />-->
-            <!--<Rectangle Name="PART_ColumnHeadersAndRowsSeparator"
+            <Rectangle Name="PART_ColumnHeadersAndRowsSeparator"
                        Grid.ColumnSpan="3"
                        VerticalAlignment="Bottom"
-                       StrokeThickness="1"
                        Height="1"
-                       Fill="{DynamicResource DataGridGridLinesBrush}" />-->
-            <Border Name="PART_ColumnHeadersAndRowsSeparator"
-                    Grid.ColumnSpan="3"
-                    Height="2"
-                    VerticalAlignment="Bottom"
-                    BorderThickness="0,0,0,1"
-                    BorderBrush="{DynamicResource DataGridGridLinesBrush}" />
+                       Fill="{DynamicResource DataGridGridLinesBrush}" />
 
             <DataGridRowsPresenter Name="PART_RowsPresenter"
                                    Grid.Row="1"
@@ -642,4 +635,14 @@
       </ControlTemplate>
     </Setter>
   </Style>
+
+  <Style Selector="DataGrid:empty-columns /template/ DataGridColumnHeader#PART_TopLeftCornerHeader">
+    <Setter Property="IsVisible" Value="False" />
+  </Style>
+  <Style Selector="DataGrid:empty-columns /template/ DataGridColumnHeadersPresenter#PART_ColumnHeadersPresenter">
+    <Setter Property="IsVisible" Value="False" />
+  </Style>
+  <Style Selector="DataGrid:empty-columns /template/ Rectangle#PART_ColumnHeadersAndRowsSeparator">
+    <Setter Property="IsVisible" Value="False" />
+  </Style>
 </Styles>

+ 5 - 4
src/Avalonia.Controls/Calendar/CalendarDatePicker.cs

@@ -420,7 +420,7 @@ namespace Avalonia.Controls
                 _calendar.DayButtonMouseUp -= Calendar_DayButtonMouseUp;
                 _calendar.DisplayDateChanged -= Calendar_DisplayDateChanged;
                 _calendar.SelectedDatesChanged -= Calendar_SelectedDatesChanged;
-                _calendar.PointerPressed -= Calendar_PointerPressed;
+                _calendar.PointerReleased -= Calendar_PointerReleased;
                 _calendar.KeyDown -= Calendar_KeyDown;
             }
             _calendar = e.NameScope.Find<Calendar>(ElementCalendar);
@@ -435,7 +435,7 @@ namespace Avalonia.Controls
                 _calendar.DayButtonMouseUp += Calendar_DayButtonMouseUp;
                 _calendar.DisplayDateChanged += Calendar_DisplayDateChanged;
                 _calendar.SelectedDatesChanged += Calendar_SelectedDatesChanged;
-                _calendar.PointerPressed += Calendar_PointerPressed;
+                _calendar.PointerReleased += Calendar_PointerReleased;
                 _calendar.KeyDown += Calendar_KeyDown;
                 //_calendar.SizeChanged += new SizeChangedEventHandler(Calendar_SizeChanged);
                 //_calendar.IsTabStop = true;
@@ -831,9 +831,10 @@ namespace Avalonia.Controls
                 }
             }
         }
-        private void Calendar_PointerPressed(object sender, PointerPressedEventArgs e)
+        private void Calendar_PointerReleased(object sender, PointerReleasedEventArgs e)
         {
-            if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
+             
+            if (e.InitialPressMouseButton == MouseButton.Left)
             {
                 e.Handled = true;
             }

+ 2 - 2
src/Avalonia.Controls/ComboBox.cs

@@ -257,7 +257,7 @@ namespace Avalonia.Controls
         }
 
         /// <inheritdoc/>
-        protected override void OnPointerPressed(PointerPressedEventArgs e)
+        protected override void OnPointerReleased(PointerReleasedEventArgs e)
         {
             if (!e.Handled)
             {
@@ -276,7 +276,7 @@ namespace Avalonia.Controls
                 }
             }
 
-            base.OnPointerPressed(e);
+            base.OnPointerReleased(e);
         }
 
         /// <inheritdoc/>

+ 3 - 1
src/Avalonia.Themes.Default/ComboBox.xaml

@@ -26,6 +26,7 @@
     <Setter Property="Padding" Value="4" />
     <Setter Property="MinHeight" Value="20" />
     <Setter Property="PlaceholderForeground" Value="{DynamicResource ThemeForegroundBrush}" />
+    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
     <Setter Property="Template">
       <ControlTemplate>
         <Border Name="border"
@@ -69,7 +70,8 @@
                    IsLightDismissEnabled="True">
               <Border BorderBrush="{DynamicResource ThemeBorderMidBrush}"
                       BorderThickness="1">
-                <ScrollViewer>
+                <ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
+                              VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
                   <ItemsPresenter Name="PART_ItemsPresenter"
                                   Items="{TemplateBinding Items}"
                                   ItemsPanel="{TemplateBinding ItemsPanel}"

+ 2 - 1
src/Avalonia.Themes.Fluent/ComboBox.xaml

@@ -133,7 +133,8 @@
                     Padding="{DynamicResource ComboBoxDropdownBorderPadding}"
                     HorizontalAlignment="Stretch"
                     CornerRadius="{DynamicResource OverlayCornerRadius}">
-              <ScrollViewer>
+              <ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
+                            VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
                 <ItemsPresenter Name="PART_ItemsPresenter"
                                 Items="{TemplateBinding Items}"
                                 Margin="{DynamicResource ComboBoxDropdownContentMargin}"

+ 1 - 1
tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs

@@ -2,7 +2,6 @@ using Avalonia.Controls.Presenters;
 using Avalonia.Controls.Primitives;
 using Avalonia.Controls.Shapes;
 using Avalonia.Controls.Templates;
-using Avalonia.Input;
 using Avalonia.LogicalTree;
 using Avalonia.Media;
 using Avalonia.UnitTests;
@@ -27,6 +26,7 @@ namespace Avalonia.Controls.UnitTests
             Assert.True(target.IsDropDownOpen);
 
             _helper.Down(target);
+            _helper.Up(target);
 
             Assert.False(target.IsDropDownOpen);
         }