Skip to content

Commit

Permalink
Merge pull request #7094 from timunie/fix/DataGridHeaderToBeStyledPro…
Browse files Browse the repository at this point in the history
…perty

fix: Make DataGridColumn.Header and .HeaderTemplate a DirectProperty
  • Loading branch information
maxkatz6 authored Dec 7, 2021
2 parents 0ca2f3d + 6d43803 commit 721b7dc
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions src/Avalonia.Controls.DataGrid/DataGridColumn.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (c) Copyright Microsoft Corporation.
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
Expand Down Expand Up @@ -400,45 +400,40 @@ public Classes CellStyleClasses
}
}

/// <summary>
/// Backing field for Header property
/// </summary>
public static readonly DirectProperty<DataGridColumn, object> HeaderProperty =
AvaloniaProperty.RegisterDirect<DataGridColumn, object>(
nameof(Header),
o => o.Header,
(o, v) => o.Header = v);

/// <summary>
/// Gets or sets the <see cref="DataGridColumnHeader"/> content
/// </summary>
public object Header
{
get
{
return _header;
}
set
{
if (_header != value)
{
_header = value;
if (_headerCell != null)
{
_headerCell.Content = value;
}
}
}
get { return _header; }
set { SetAndRaise(HeaderProperty, ref _header, value); }
}

/// <summary>
/// Backing field for Header property
/// </summary>
public static readonly DirectProperty<DataGridColumn, IDataTemplate> HeaderTemplateProperty =
AvaloniaProperty.RegisterDirect<DataGridColumn, IDataTemplate>(
nameof(HeaderTemplate),
o => o.HeaderTemplate,
(o, v) => o.HeaderTemplate = v);

/// <summary>
/// Gets or sets an <see cref="IDataTemplate"/> for the <see cref="Header"/>
/// </summary>
public IDataTemplate HeaderTemplate
{
get
{
return _headerTemplate;
}
set
{
if (_headerTemplate != value)
{
_headerTemplate = value;
if (_headerCell != null)
{
_headerCell.ContentTemplate = value;
}
}
}
get { return _headerTemplate; }
set { SetAndRaise(HeaderTemplateProperty, ref _headerTemplate, value); }
}

public bool IsAutoGenerated
Expand Down Expand Up @@ -874,10 +869,11 @@ internal virtual DataGridColumnHeader CreateHeader()
{
var result = new DataGridColumnHeader
{
OwningColumn = this,
Content = _header,
ContentTemplate = _headerTemplate
OwningColumn = this
};
result[!ContentControl.ContentProperty] = this[!HeaderProperty];
result[!ContentControl.ContentTemplateProperty] = this[!HeaderTemplateProperty];

//result.EnsureStyle(null);

return result;
Expand Down

0 comments on commit 721b7dc

Please sign in to comment.