diff --git a/src/Avalonia.Base/Utilities/MathUtilities.cs b/src/Avalonia.Base/Utilities/MathUtilities.cs
index 2f138d9e83..dc47584f32 100644
--- a/src/Avalonia.Base/Utilities/MathUtilities.cs
+++ b/src/Avalonia.Base/Utilities/MathUtilities.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
+using System.Runtime.InteropServices;
namespace Avalonia.Utilities
{
@@ -12,17 +13,8 @@ namespace Avalonia.Utilities
{
///
/// AreClose - Returns whether or not two doubles are "close". That is, whether or
- /// not they are within epsilon of each other. Note that this epsilon is proportional
- /// to the numbers themselves to that AreClose survives scalar multiplication.
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false. This is important enough to repeat:
- /// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
- /// used for optimizations *only*.
- ///
- ///
- /// bool - the result of the AreClose comparision.
- ///
+ /// not they are within epsilon of each other.
+ ///
/// The first double to compare.
/// The second double to compare.
public static bool AreClose(double value1, double value2)
@@ -37,17 +29,7 @@ namespace Avalonia.Utilities
///
/// LessThan - Returns whether or not the first double is less than the second double.
/// That is, whether or not the first is strictly less than *and* not within epsilon of
- /// the other number. Note that this epsilon is proportional to the numbers themselves
- /// to that AreClose survives scalar multiplication. Note,
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false. This is important enough to repeat:
- /// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
- /// used for optimizations *only*.
- ///
- ///
- /// bool - the result of the LessThan comparision.
- ///
+ /// the other number.
/// The first double to compare.
/// The second double to compare.
public static bool LessThan(double value1, double value2)
@@ -55,15 +37,10 @@ namespace Avalonia.Utilities
return (value1 < value2) && !AreClose(value1, value2);
}
-
///
/// GreaterThan - Returns whether or not the first double is greater than the second double.
/// That is, whether or not the first is strictly greater than *and* not within epsilon of
- /// the other number. Note that this epsilon is proportional to the numbers themselves
- /// to that AreClose survives scalar multiplication.
- ///
- /// - the result of the GreaterThan comparision.
- ///
+ /// the other number.
/// The first double to compare.
/// The second double to compare.
public static bool GreaterThan(double value1, double value2)
@@ -74,17 +51,7 @@ namespace Avalonia.Utilities
///
/// LessThanOrClose - Returns whether or not the first double is less than or close to
/// the second double. That is, whether or not the first is strictly less than or within
- /// epsilon of the other number. Note that this epsilon is proportional to the numbers
- /// themselves to that AreClose survives scalar multiplication. Note,
- /// There are plenty of ways for this to return false even for numbers which
- /// are theoretically identical, so no code calling this should fail to work if this
- /// returns false. This is important enough to repeat:
- /// NB: NO CODE CALLING THIS FUNCTION SHOULD DEPEND ON ACCURATE RESULTS - this should be
- /// used for optimizations *only*.
- ///
- ///
- /// bool - the result of the LessThanOrClose comparision.
- ///
+ /// epsilon of the other number.
/// The first double to compare.
/// The second double to compare.
public static bool LessThanOrClose(double value1, double value2)
@@ -99,7 +66,6 @@ namespace Avalonia.Utilities
///
/// The first double to compare.
/// The second double to compare.
- /// the result of the GreaterThanOrClose comparision.
public static bool GreaterThanOrClose(double value1, double value2)
{
return (value1 > value2) || AreClose(value1, value2);
@@ -109,9 +75,6 @@ namespace Avalonia.Utilities
/// IsOne - Returns whether or not the double is "close" to 1. Same as AreClose(double, 1),
/// but this is faster.
///
- ///
- /// bool - the result of the AreClose comparision.
- ///
/// The double to compare to 1.
public static bool IsOne(double value)
{
@@ -122,9 +85,6 @@ namespace Avalonia.Utilities
/// IsZero - Returns whether or not the double is "close" to 0. Same as AreClose(double, 0),
/// but this is faster.
///
- ///
- /// bool - the result of the AreClose comparision.
- ///
/// The double to compare to 0.
public static bool IsZero(double value)
{
diff --git a/src/Avalonia.Controls/DefinitionBase.cs b/src/Avalonia.Controls/DefinitionBase.cs
index 10d6b55285..e1c5979476 100644
--- a/src/Avalonia.Controls/DefinitionBase.cs
+++ b/src/Avalonia.Controls/DefinitionBase.cs
@@ -12,7 +12,7 @@ namespace Avalonia.Controls
///
/// Base class for and .
///
- public class DefinitionBase : AvaloniaObject
+ public class DefinitionBase : ContentControl
{
///
@@ -307,7 +307,7 @@ namespace Avalonia.Controls
///
/// Layout-time user size type.
///
- internal Grid.LayoutTimeSizeType SizeType
+ internal Grid.GridLayoutTimeSizeType SizeType
{
get { return (_sizeType); }
set { _sizeType = value; }
@@ -333,7 +333,7 @@ namespace Avalonia.Controls
get
{
double preferredSize = MinSize;
- if (_sizeType != Grid.LayoutTimeSizeType.Auto
+ if (_sizeType != Grid.GridLayoutTimeSizeType.Auto
&& preferredSize < _measureSize)
{
preferredSize = _measureSize;
@@ -635,7 +635,7 @@ namespace Avalonia.Controls
private Flags _flags; // flags reflecting various aspects of internal state
private int _parentIndex; // this instance's index in parent's children collection
- private Grid.LayoutTimeSizeType _sizeType; // layout-time user size type. it may differ from _userSizeValueCache.UnitType when calculating "to-content"
+ private Grid.GridLayoutTimeSizeType _sizeType; // layout-time user size type. it may differ from _userSizeValueCache.UnitType when calculating "to-content"
private double _minSize; // used during measure to accumulate size for "Auto" and "Star" DefinitionBase's
private double _measureSize; // size, calculated to be the input contstraint size for Child.Measure
diff --git a/src/Avalonia.Controls/GridWPF.cs b/src/Avalonia.Controls/GridWPF.cs
index 30ca751e57..5364f99dae 100644
--- a/src/Avalonia.Controls/GridWPF.cs
+++ b/src/Avalonia.Controls/GridWPF.cs
@@ -56,6 +56,14 @@ namespace Avalonia.Controls
public static readonly AttachedProperty IsSharedSizeScopeProperty =
AvaloniaProperty.RegisterAttached("IsSharedSizeScope", false);
+ ///
+ /// Defines the property.
+ ///
+ public static readonly StyledProperty ShowGridLinesProperty =
+ AvaloniaProperty.Register(
+ nameof(ShowGridLines),
+ defaultValue: false);
+
///
/// ShowGridLines property.
///
@@ -64,6 +72,7 @@ namespace Avalonia.Controls
get { return (CheckFlagsAnd(Flags.ShowGridLinesPropertyValue)); }
set { SetValue(ShowGridLinesProperty, value); }
}
+
private ColumnDefinitions _columnDefinitions;
private RowDefinitions _rowDefinitions;
@@ -1135,10 +1144,10 @@ namespace Avalonia.Controls
// sanity check: totalRemainingSize and sizeToDistribute must be real positive numbers
Debug.Assert(!double.IsInfinity(totalRemainingSize)
- && !MathUtilities.IsNaN(totalRemainingSize)
+ && !double.IsNaN(totalRemainingSize)
&& totalRemainingSize > 0
&& !double.IsInfinity(sizeToDistribute)
- && !MathUtilities.IsNaN(sizeToDistribute)
+ && !double.IsNaN(sizeToDistribute)
&& sizeToDistribute > 0);
for (int i = 0; i < count; ++i)
@@ -1163,15 +1172,6 @@ namespace Avalonia.Controls
}
}
- ///
- /// Resolves Star's for given array of definitions.
- ///
- /// Array of definitions to resolve stars.
- /// All available size.
- ///
- /// Must initialize LayoutSize for all Star entries in given array of definitions.
- ///
-
// new implementation as of 4.7. Several improvements:
// 1. Allocate to *-defs hitting their min or max constraints, before allocating
// to other *-defs. A def that hits its min uses more space than its
@@ -1186,6 +1186,14 @@ namespace Avalonia.Controls
// change in available space resulting in large change to one def's allocation.
// 3. Correct handling of large *-values, including Infinity.
+ ///
+ /// Resolves Star's for given array of definitions.
+ ///
+ /// Array of definitions to resolve stars.
+ /// All available size.
+ ///
+ /// Must initialize LayoutSize for all Star entries in given array of definitions.
+ ///
private void ResolveStar(
DefinitionBase[] definitions,
double availableSize)
@@ -2113,12 +2121,30 @@ namespace Avalonia.Controls
return (flags == 0 || (_flags & flags) != 0);
}
- ///
- ///
- ///
- private static void OnShowGridLinesPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+
+ private static int ValidateColumn(AvaloniaObject o, int value)
{
- Grid grid = (Grid)d;
+ if (value < 0)
+ {
+ throw new ArgumentException("Invalid Grid.Column value.");
+ }
+
+ return value;
+ }
+
+ private static int ValidateRow(AvaloniaObject o, int value)
+ {
+ if (value < 0)
+ {
+ throw new ArgumentException("Invalid Grid.Row value.");
+ }
+
+ return value;
+ }
+
+ private static void OnShowGridLinesPropertyChanged(AvaloniaPropertyChangedEventArgs e)
+ {
+ var grid = e.Sender as Grid;
if (grid.ExtData != null // trivial grid is 1 by 1. there is no grid lines anyway
&& grid.ListenToNotifications)
@@ -2129,12 +2155,9 @@ namespace Avalonia.Controls
grid.SetFlags((bool)e.NewValue, Flags.ShowGridLinesPropertyValue);
}
- ///
- ///
- ///
- private static void OnCellAttachedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ private static void OnCellAttachedPropertyChanged(AvaloniaPropertyChangedEventArgs e)
{
- Visual child = d as Visual;
+ var child = e.Sender as Visual;
if (child != null)
{
@@ -2149,22 +2172,6 @@ namespace Avalonia.Controls
}
}
- ///
- ///
- ///
- private static bool IsIntValueNotNegative(object value)
- {
- return ((int)value >= 0);
- }
-
- ///
- ///
- ///
- private static bool IsIntValueGreaterThanZero(object value)
- {
- return ((int)value > 0);
- }
-
///
/// Helper for Comparer methods.
///