From c25a130903faca7764b7e45f8b13e9fd3fde04fa Mon Sep 17 00:00:00 2001 From: GMIKE Date: Tue, 1 Sep 2020 01:07:49 +0300 Subject: [PATCH 01/26] Useful methods and operations --- src/Avalonia.Visuals/Point.cs | 115 ++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/src/Avalonia.Visuals/Point.cs b/src/Avalonia.Visuals/Point.cs index 4cce2c925b..f9ae1f2fe1 100644 --- a/src/Avalonia.Visuals/Point.cs +++ b/src/Avalonia.Visuals/Point.cs @@ -76,6 +76,17 @@ namespace Avalonia return left.Equals(right); } + /// + /// Checks for equality between a point and cortege off double numbers s. + /// + /// The point. + /// Cortege off double numbers + /// True if the point and cortege off double numbers are equal; otherwise false. + public static bool operator ==(Point left, (double x, double y) right) + { + return !((left._x.Equals(right.x)) && (left._y.Equals(right.y))); + } + /// /// Checks for inequality between two s. /// @@ -87,6 +98,17 @@ namespace Avalonia return !(left == right); } + /// + /// Checks for inequality between a point and cortege off double numberss. + /// + /// The point. + /// Cortege off double numbers + /// True if the point and cortege off double numbers are unequal; otherwise false. + public static bool operator !=(Point left, (double x, double y) right) + { + return !((left._x == right.x) && (left._y== right.y)); + } + /// /// Adds two points. /// @@ -109,6 +131,28 @@ namespace Avalonia return new Point(a._x + b.X, a._y + b.Y); } + /// + /// Add a cortege off double numbers + /// + /// The point. + /// cortege off doubles + /// A point that is the result of the addition. + public static Point operator +(Point a, (double x, double y) b) + { + return new Point(a._x + b.x, a._y + b.y); + } + + /// + /// Add a double number to both coordinates + /// + /// The point. + /// double number + /// A point that is the result of the addition. + public static Point operator +(Point a, double b) + { + return new Point(a._x + b, a._y + b); + } + /// /// Subtracts two points. /// @@ -131,6 +175,28 @@ namespace Avalonia return new Point(a._x - b.X, a._y - b.Y); } + /// + /// Subtracts a cortege off double numbers + /// + /// The point. + /// cortege off doubles + /// A point that is the result of the subtraction. + public static Point operator -(Point a, (double x, double y) b) + { + return new Point(a._x - b.x, a._y - b.y); + } + + /// + /// Subtracts a double number to both coordinates + /// + /// The point. + /// double number + /// A point that is the result of the subtraction. + public static Point operator -(Point a, double b) + { + return new Point(a._x - b, a._y - b); + } + /// /// Multiplies a point by a factor coordinate-wise /// @@ -147,6 +213,17 @@ namespace Avalonia /// Points having its coordinates multiplied public static Point operator *(double k, Point p) => new Point(p.X * k, p.Y * k); + /// + /// Multiplies a cortege off double numbers + /// + /// The point. + /// cortege off doubles + /// Points having its coordinates multiplied. + public static Point operator *(Point a, (double x, double y) b) + { + return new Point(a._x * b.x, a._y * b.y); + } + /// /// Divides a point by a factor coordinate-wise /// @@ -155,6 +232,17 @@ namespace Avalonia /// Points having its coordinates divided public static Point operator /(Point p, double k) => new Point(p.X / k, p.Y / k); + /// + /// Divides a point by a cortege off double numbers + /// + /// The point. + /// cortege off doubles + /// Points having its coordinates divided + public static Point operator /(Point a, (double x, double y) b) + { + return new Point(a._x / b.x, a._y / b.y); + } + /// /// Applies a matrix to a point. /// @@ -267,5 +355,32 @@ namespace Avalonia { return new Point(_x, y); } + + /// + /// Returns a new point with the opposite coordinates. + /// + /// The new point. + public Point Miror() + { + return new Point(-_x, -_y); + } + + /// + /// Returns a new point with the opposite X coordinate. + /// + /// The new point. + public Point WithMirorX() + { + return new Point(-_x, _y); + } + + /// + /// Returns a new point with the opposite Y coordinate. + /// + /// The new point. + public Point WithMirorY() + { + return new Point(_x, -_y); + } } } From 8e03d121ac1357d94e9ece9fcd2e06d9b175c264 Mon Sep 17 00:00:00 2001 From: GMIKE Date: Tue, 1 Sep 2020 14:10:20 +0300 Subject: [PATCH 02/26] Deconstruct and IsEmpty propterty --- src/Avalonia.Visuals/Point.cs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Avalonia.Visuals/Point.cs b/src/Avalonia.Visuals/Point.cs index f9ae1f2fe1..2e77f5528b 100644 --- a/src/Avalonia.Visuals/Point.cs +++ b/src/Avalonia.Visuals/Point.cs @@ -357,30 +357,22 @@ namespace Avalonia } /// - /// Returns a new point with the opposite coordinates. + /// Deconstructor for decomposition Point /// - /// The new point. - public Point Miror() - { - return new Point(-_x, -_y); - } - - /// - /// Returns a new point with the opposite X coordinate. - /// - /// The new point. - public Point WithMirorX() + /// The X position. + /// The Y position. + public void Deconstruct(out double x, out double y) { - return new Point(-_x, _y); + x = this._x; + y = this._y; } /// - /// Returns a new point with the opposite Y coordinate. + /// Gets a value indicating that Point coordinatrs is zero /// - /// The new point. - public Point WithMirorY() + public bool IsEmpty { - return new Point(_x, -_y); + get { return (_x == 0) && (_y == 0); } } } } From a339c68e8cb5ac4741a6bff936b0b462f1a155ca Mon Sep 17 00:00:00 2001 From: GMIKE Date: Tue, 1 Sep 2020 16:18:15 +0300 Subject: [PATCH 03/26] Equals for cortege off double numbers --- src/Avalonia.Visuals/Point.cs | 44 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/Avalonia.Visuals/Point.cs b/src/Avalonia.Visuals/Point.cs index 2e77f5528b..52fd4d05c9 100644 --- a/src/Avalonia.Visuals/Point.cs +++ b/src/Avalonia.Visuals/Point.cs @@ -8,7 +8,7 @@ namespace Avalonia /// /// Defines a point. /// - public readonly struct Point : IEquatable + public readonly struct Point : IEquatable, IEquatable<(double x,double y)> { static Point() { @@ -76,17 +76,6 @@ namespace Avalonia return left.Equals(right); } - /// - /// Checks for equality between a point and cortege off double numbers s. - /// - /// The point. - /// Cortege off double numbers - /// True if the point and cortege off double numbers are equal; otherwise false. - public static bool operator ==(Point left, (double x, double y) right) - { - return !((left._x.Equals(right.x)) && (left._y.Equals(right.y))); - } - /// /// Checks for inequality between two s. /// @@ -98,17 +87,6 @@ namespace Avalonia return !(left == right); } - /// - /// Checks for inequality between a point and cortege off double numberss. - /// - /// The point. - /// Cortege off double numbers - /// True if the point and cortege off double numbers are unequal; otherwise false. - public static bool operator !=(Point left, (double x, double y) right) - { - return !((left._x == right.x) && (left._y== right.y)); - } - /// /// Adds two points. /// @@ -367,6 +345,26 @@ namespace Avalonia y = this._y; } + /// + /// Returns a boolean indicating whether the point is equal to the other given point. + /// + /// The other point to test equality against. + /// True if this point is equal to other; False otherwise. + + + /// + /// Returns a boolean indicating whether the point is equal to cortege off double numbers. + /// + /// Ñortege off double numbers + /// + /// True if is cortege off double numbersthat equals the current point. + /// + public bool Equals((double x, double y) other) + { + return _x == other.x && + _y == other.y; + } + /// /// Gets a value indicating that Point coordinatrs is zero /// From 031722ebb2f98cedb391aa628e4e7c06fb633a33 Mon Sep 17 00:00:00 2001 From: GMIKE Date: Wed, 2 Sep 2020 19:12:28 +0300 Subject: [PATCH 04/26] Change IsEmpty on IsDefault --- src/Avalonia.Visuals/Point.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Avalonia.Visuals/Point.cs b/src/Avalonia.Visuals/Point.cs index 52fd4d05c9..ae713e57a5 100644 --- a/src/Avalonia.Visuals/Point.cs +++ b/src/Avalonia.Visuals/Point.cs @@ -345,19 +345,12 @@ namespace Avalonia y = this._y; } - /// - /// Returns a boolean indicating whether the point is equal to the other given point. - /// - /// The other point to test equality against. - /// True if this point is equal to other; False otherwise. - - /// /// Returns a boolean indicating whether the point is equal to cortege off double numbers. /// /// Ñortege off double numbers /// - /// True if is cortege off double numbersthat equals the current point. + /// True if is cortege off double numbersthat equals the current point. /// public bool Equals((double x, double y) other) { @@ -368,7 +361,7 @@ namespace Avalonia /// /// Gets a value indicating that Point coordinatrs is zero /// - public bool IsEmpty + public bool IsDefault { get { return (_x == 0) && (_y == 0); } } From 115c4adadbb5f3d9cadbe53cdb78e617d9602d45 Mon Sep 17 00:00:00 2001 From: GMIKE Date: Wed, 2 Sep 2020 19:51:18 +0300 Subject: [PATCH 05/26] fix for xml --- src/Avalonia.Visuals/Point.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Avalonia.Visuals/Point.cs b/src/Avalonia.Visuals/Point.cs index ae713e57a5..d95512c976 100644 --- a/src/Avalonia.Visuals/Point.cs +++ b/src/Avalonia.Visuals/Point.cs @@ -110,10 +110,10 @@ namespace Avalonia } /// - /// Add a cortege off double numbers + /// Add a 2-tuple of double /// /// The point. - /// cortege off doubles + /// 2-tuple of double /// A point that is the result of the addition. public static Point operator +(Point a, (double x, double y) b) { @@ -154,10 +154,10 @@ namespace Avalonia } /// - /// Subtracts a cortege off double numbers + /// Subtracts a 2-tuple of double /// /// The point. - /// cortege off doubles + /// 2-tuple of double /// A point that is the result of the subtraction. public static Point operator -(Point a, (double x, double y) b) { @@ -192,10 +192,10 @@ namespace Avalonia public static Point operator *(double k, Point p) => new Point(p.X * k, p.Y * k); /// - /// Multiplies a cortege off double numbers + /// Multiplies a 2-tuple of double /// /// The point. - /// cortege off doubles + /// 2-tuple of double /// Points having its coordinates multiplied. public static Point operator *(Point a, (double x, double y) b) { @@ -211,10 +211,10 @@ namespace Avalonia public static Point operator /(Point p, double k) => new Point(p.X / k, p.Y / k); /// - /// Divides a point by a cortege off double numbers + /// Divides a point by a 2-tuple of doubles /// /// The point. - /// cortege off doubles + /// 2-tuple of double /// Points having its coordinates divided public static Point operator /(Point a, (double x, double y) b) { @@ -346,11 +346,11 @@ namespace Avalonia } /// - /// Returns a boolean indicating whether the point is equal to cortege off double numbers. + /// Returns a boolean indicating whether the point coordinates are equal to 2-tuple of double /// - /// Ñortege off double numbers + /// 2-tuple of double /// - /// True if is cortege off double numbersthat equals the current point. + /// True if is 2-tuple of double equals coordinates current point. /// public bool Equals((double x, double y) other) { @@ -359,7 +359,7 @@ namespace Avalonia } /// - /// Gets a value indicating that Point coordinatrs is zero + /// Gets a value indicating that point coordinates are zero /// public bool IsDefault { From f33e12c22996fbe3a23938462f5fe66de41df9fd Mon Sep 17 00:00:00 2001 From: Maksym Katsydan Date: Fri, 11 Sep 2020 04:05:05 -0400 Subject: [PATCH 06/26] DataGridTextColumn: Make FontFamily, FontSize, FontStyle, FontWeight and Foreground properties bindable --- .../ApiCompatBaseline.txt | 5 + .../DataGridTextColumn.cs | 231 +++++------------- .../Utils/DataGridHelper.cs | 22 ++ 3 files changed, 92 insertions(+), 166 deletions(-) create mode 100644 src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt create mode 100644 src/Avalonia.Controls.DataGrid/Utils/DataGridHelper.cs diff --git a/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt b/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt new file mode 100644 index 0000000000..82472c505a --- /dev/null +++ b/src/Avalonia.Controls.DataGrid/ApiCompatBaseline.txt @@ -0,0 +1,5 @@ +Compat issues with assembly Avalonia.Controls.DataGrid: +MembersMustExist : Member 'public Avalonia.StyledProperty Avalonia.StyledProperty Avalonia.Controls.DataGridTextColumn.FontFamilyProperty' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public System.String Avalonia.Controls.DataGridTextColumn.FontFamily.get()' does not exist in the implementation but it does exist in the contract. +MembersMustExist : Member 'public void Avalonia.Controls.DataGridTextColumn.FontFamily.set(System.String)' does not exist in the implementation but it does exist in the contract. +Total Issues: 3 diff --git a/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs index d31204b9e6..1cf6ab68ac 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridTextColumn.cs @@ -20,11 +20,6 @@ namespace Avalonia.Controls { private const string DATAGRID_TextColumnCellTextBlockMarginKey = "DataGridTextColumnCellTextBlockMargin"; - private double? _fontSize; - private FontStyle? _fontStyle; - private FontWeight? _fontWeight; - private IBrush _foreground; - /// /// Initializes a new instance of the class. /// @@ -36,18 +31,24 @@ namespace Avalonia.Controls /// /// Identifies the FontFamily dependency property. /// - public static readonly StyledProperty FontFamilyProperty = - AvaloniaProperty.Register(nameof(FontFamily)); + public static readonly AttachedProperty FontFamilyProperty = + TextBlock.FontFamilyProperty.AddOwner(); /// /// Gets or sets the font name. /// - public string FontFamily + public FontFamily FontFamily { - get { return GetValue(FontFamilyProperty); } - set { SetValue(FontFamilyProperty, value); } + get => GetValue(FontFamilyProperty); + set => SetValue(FontFamilyProperty, value); } + /// + /// Identifies the FontSize dependency property. + /// + public static readonly AttachedProperty FontSizeProperty = + TextBlock.FontSizeProperty.AddOwner(); + /// /// Gets or sets the font size. /// @@ -55,74 +56,66 @@ namespace Avalonia.Controls [DefaultValue(double.NaN)] public double FontSize { - get - { - return _fontSize ?? Double.NaN; - } - set - { - if (_fontSize != value) - { - _fontSize = value; - NotifyPropertyChanged(nameof(FontSize)); - } - } + get => GetValue(FontSizeProperty); + set => SetValue(FontSizeProperty, value); } + /// + /// Identifies the FontStyle dependency property. + /// + public static readonly AttachedProperty FontStyleProperty = + TextBlock.FontStyleProperty.AddOwner(); + /// /// Gets or sets the font style. /// public FontStyle FontStyle { - get - { - return _fontStyle ?? FontStyle.Normal; - } - set - { - if (_fontStyle != value) - { - _fontStyle = value; - NotifyPropertyChanged(nameof(FontStyle)); - } - } + get => GetValue(FontStyleProperty); + set => SetValue(FontStyleProperty, value); } + /// + /// Identifies the FontWeight dependency property. + /// + public static readonly AttachedProperty FontWeightProperty = + TextBlock.FontWeightProperty.AddOwner(); + /// /// Gets or sets the font weight or thickness. /// public FontWeight FontWeight { - get - { - return _fontWeight ?? FontWeight.Normal; - } - set - { - if (_fontWeight != value) - { - _fontWeight = value; - NotifyPropertyChanged(nameof(FontWeight)); - } - } + get => GetValue(FontWeightProperty); + set => SetValue(FontWeightProperty, value); } + /// + /// Identifies the Foreground dependency property. + /// + public static readonly AttachedProperty ForegroundProperty = + TextBlock.ForegroundProperty.AddOwner(); + /// /// Gets or sets a brush that describes the foreground of the column cells. /// public IBrush Foreground { - get - { - return _foreground; - } - set + get => GetValue(ForegroundProperty); + set => SetValue(ForegroundProperty, value); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == FontFamilyProperty + || change.Property == FontSizeProperty + || change.Property == FontStyleProperty + || change.Property == FontWeightProperty + || change.Property == ForegroundProperty) { - if (_foreground != value) - { - _foreground = value; - NotifyPropertyChanged(nameof(Foreground)); - } + NotifyPropertyChanged(change.Property.Name); } } @@ -154,26 +147,7 @@ namespace Avalonia.Controls Background = new SolidColorBrush(Colors.Transparent) }; - if (IsSet(FontFamilyProperty)) - { - textBox.FontFamily = FontFamily; - } - if (_fontSize.HasValue) - { - textBox.FontSize = _fontSize.Value; - } - if (_fontStyle.HasValue) - { - textBox.FontStyle = _fontStyle.Value; - } - if (_fontWeight.HasValue) - { - textBox.FontWeight = _fontWeight.Value; - } - if (_foreground != null) - { - textBox.Foreground = _foreground; - } + SyncProperties(textBox); return textBox; } @@ -192,26 +166,8 @@ namespace Avalonia.Controls VerticalAlignment = VerticalAlignment.Center }; - if (IsSet(FontFamilyProperty)) - { - textBlockElement.FontFamily = FontFamily; - } - if (_fontSize.HasValue) - { - textBlockElement.FontSize = _fontSize.Value; - } - if (_fontStyle.HasValue) - { - textBlockElement.FontStyle = _fontStyle.Value; - } - if (_fontWeight.HasValue) - { - textBlockElement.FontWeight = _fontWeight.Value; - } - if (_foreground != null) - { - textBlockElement.Foreground = _foreground; - } + SyncProperties(textBlockElement); + if (Binding != null) { textBlockElement.Bind(TextBlock.TextProperty, Binding); @@ -261,99 +217,42 @@ namespace Avalonia.Controls throw new ArgumentNullException("element"); } - if(element is TextBox textBox) + if (element is AvaloniaObject content) { if (propertyName == nameof(FontFamily)) { - textBox.FontFamily = FontFamily; + DataGridHelper.SyncColumnProperty(this, content, FontFamilyProperty); } else if (propertyName == nameof(FontSize)) { - SetTextFontSize(textBox, TextBox.FontSizeProperty); + DataGridHelper.SyncColumnProperty(this, content, FontSizeProperty); } else if (propertyName == nameof(FontStyle)) { - textBox.FontStyle = FontStyle; + DataGridHelper.SyncColumnProperty(this, content, FontStyleProperty); } else if (propertyName == nameof(FontWeight)) { - textBox.FontWeight = FontWeight; + DataGridHelper.SyncColumnProperty(this, content, FontWeightProperty); } else if (propertyName == nameof(Foreground)) { - textBox.Foreground = Foreground; - } - else - { - if (FontFamily != null) - { - textBox.FontFamily = FontFamily; - } - SetTextFontSize(textBox, TextBox.FontSizeProperty); - textBox.FontStyle = FontStyle; - textBox.FontWeight = FontWeight; - if (Foreground != null) - { - textBox.Foreground = Foreground; - } - } - - } - else if (element is TextBlock textBlock) - { - if (propertyName == nameof(FontFamily)) - { - textBlock.FontFamily = FontFamily; - } - else if (propertyName == nameof(FontSize)) - { - SetTextFontSize(textBlock, TextBlock.FontSizeProperty); - } - else if (propertyName == nameof(FontStyle)) - { - textBlock.FontStyle = FontStyle; - } - else if (propertyName == nameof(FontWeight)) - { - textBlock.FontWeight = FontWeight; - } - else if (propertyName == nameof(Foreground)) - { - textBlock.Foreground = Foreground; - } - else - { - if (FontFamily != null) - { - textBlock.FontFamily = FontFamily; - } - SetTextFontSize(textBlock, TextBlock.FontSizeProperty); - textBlock.FontStyle = FontStyle; - textBlock.FontWeight = FontWeight; - if (Foreground != null) - { - textBlock.Foreground = Foreground; - } + DataGridHelper.SyncColumnProperty(this, content, ForegroundProperty); } } else { - throw DataGridError.DataGrid.ValueIsNotAnInstanceOfEitherOr("element", typeof(TextBox), typeof(TextBlock)); + throw DataGridError.DataGrid.ValueIsNotAnInstanceOf("element", typeof(AvaloniaObject)); } } - private void SetTextFontSize(AvaloniaObject textElement, AvaloniaProperty fontSizeProperty) + private void SyncProperties(AvaloniaObject content) { - double newFontSize = FontSize; - if (double.IsNaN(newFontSize)) - { - textElement.ClearValue(fontSizeProperty); - } - else - { - textElement.SetValue(fontSizeProperty, newFontSize); - } + DataGridHelper.SyncColumnProperty(this, content, FontFamilyProperty); + DataGridHelper.SyncColumnProperty(this, content, FontSizeProperty); + DataGridHelper.SyncColumnProperty(this, content, FontStyleProperty); + DataGridHelper.SyncColumnProperty(this, content, FontWeightProperty); + DataGridHelper.SyncColumnProperty(this, content, ForegroundProperty); } - } } diff --git a/src/Avalonia.Controls.DataGrid/Utils/DataGridHelper.cs b/src/Avalonia.Controls.DataGrid/Utils/DataGridHelper.cs new file mode 100644 index 0000000000..d553a82fa0 --- /dev/null +++ b/src/Avalonia.Controls.DataGrid/Utils/DataGridHelper.cs @@ -0,0 +1,22 @@ +namespace Avalonia.Controls +{ + public static class DataGridHelper + { + internal static void SyncColumnProperty(AvaloniaObject column, AvaloniaObject content, AvaloniaProperty property) + { + SyncColumnProperty(column, content, property, property); + } + + internal static void SyncColumnProperty(AvaloniaObject column, AvaloniaObject content, AvaloniaProperty contentProperty, AvaloniaProperty columnProperty) + { + if (!column.IsSet(columnProperty)) + { + content.ClearValue(contentProperty); + } + else + { + content.SetValue(contentProperty, column.GetValue(columnProperty)); + } + } + } +} From ab5c3dd190088d80464edbdd76bb366b7ae52bab Mon Sep 17 00:00:00 2001 From: Maksym Katsydan Date: Fri, 11 Sep 2020 04:06:10 -0400 Subject: [PATCH 07/26] DataGridCheckBoxColumn: Make IsThreeState property bindable --- .../DataGridCheckBoxColumn.cs | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs index f1bbea9949..e2a067ac61 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs @@ -17,9 +17,7 @@ namespace Avalonia.Controls /// public class DataGridCheckBoxColumn : DataGridBoundColumn { - private bool _beganEditWithKeyboard; - private bool _isThreeState; private CheckBox _currentCheckBox; private DataGrid _owningGrid; @@ -31,6 +29,12 @@ namespace Avalonia.Controls BindingTarget = CheckBox.IsCheckedProperty; } + /// + /// Defines the property. + /// + public static StyledProperty IsThreeStateProperty = + CheckBox.IsThreeStateProperty.AddOwner(); + /// /// Gets or sets a value that indicates whether the hosted controls allow three states or two. /// @@ -39,17 +43,17 @@ namespace Avalonia.Controls /// public bool IsThreeState { - get - { - return _isThreeState; - } - set + get => GetValue(IsThreeStateProperty); + set => SetValue(IsThreeStateProperty, value); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == IsThreeStateProperty) { - if (_isThreeState != value) - { - _isThreeState = value; - NotifyPropertyChanged(nameof(IsThreeState)); - } + NotifyPropertyChanged(change.Property.Name); } } @@ -203,9 +207,9 @@ namespace Avalonia.Controls { throw new ArgumentNullException("element"); } - if(element is CheckBox checkBox) + if (element is CheckBox checkBox) { - checkBox.IsThreeState = IsThreeState; + DataGridHelper.SyncColumnProperty(this, checkBox, IsThreeStateProperty); } else { @@ -229,7 +233,7 @@ namespace Avalonia.Controls { checkBox.HorizontalAlignment = HorizontalAlignment.Center; checkBox.VerticalAlignment = VerticalAlignment.Center; - checkBox.IsThreeState = IsThreeState; + DataGridHelper.SyncColumnProperty(this, checkBox, IsThreeStateProperty); } private bool EnsureOwningGrid() From fae969644a110f1a78b9d9307de9eeefa7cc86c7 Mon Sep 17 00:00:00 2001 From: Maksym Katsydan Date: Fri, 11 Sep 2020 04:11:02 -0400 Subject: [PATCH 08/26] Update DataGrid sample page to test column bindings --- samples/ControlCatalog/Pages/DataGridPage.xaml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml b/samples/ControlCatalog/Pages/DataGridPage.xaml index d045626c2c..cacc2204bd 100644 --- a/samples/ControlCatalog/Pages/DataGridPage.xaml +++ b/samples/ControlCatalog/Pages/DataGridPage.xaml @@ -11,12 +11,17 @@ - + DataGrid A control for displaying and interacting with a data source. - + + + + + + @@ -39,13 +44,13 @@ - + - - - + + +