Skip to content

Commit 5aca799

Browse files
rabbitismmaxkatz6
authored andcommitted
feat: use visual brush if Header is control. (#18154)
1 parent e0ecb44 commit 5aca799

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using Avalonia.Controls.Automation.Peers;
1313
using Avalonia.Controls.Metadata;
1414
using Avalonia.Controls.Mixins;
15+
using Avalonia.Controls.Shapes;
16+
using Avalonia.Controls.Templates;
1517
using Avalonia.Controls.Utils;
1618
using Avalonia.Data;
1719
using Avalonia.Input;
@@ -678,8 +680,7 @@ private void OnMouseMove_BeginReorder(Point mousePosition)
678680
{
679681
OwningColumn = OwningColumn,
680682
IsEnabled = false,
681-
Content = Content,
682-
ContentTemplate = ContentTemplate
683+
Content = GetDragIndicatorContent(Content, ContentTemplate)
683684
};
684685
if (OwningGrid.ColumnHeaderTheme is { } columnHeaderTheme)
685686
{
@@ -725,6 +726,36 @@ private void OnMouseMove_BeginReorder(Point mousePosition)
725726
}
726727
}
727728

729+
private object GetDragIndicatorContent(object content, IDataTemplate? dataTemplate)
730+
{
731+
if (content is ContentControl icc)
732+
{
733+
content = icc.Content;
734+
}
735+
736+
if (content is Control control)
737+
{
738+
if (VisualRoot == null) return content;
739+
control.Measure(Size.Infinity);
740+
var rect = new Rectangle()
741+
{
742+
Width = control.DesiredSize.Width,
743+
Height = control.DesiredSize.Height,
744+
Fill = new VisualBrush
745+
{
746+
Visual = control, Stretch = Stretch.None, AlignmentX = AlignmentX.Left,
747+
}
748+
};
749+
return rect;
750+
}
751+
752+
if (dataTemplate is not null)
753+
{
754+
return dataTemplate.Build(content);
755+
}
756+
return content;
757+
}
758+
728759
//TODO DragEvents
729760
private void OnMouseMove_Reorder(ref bool handled, Point mousePosition, Point mousePositionHeaders)
730761
{

0 commit comments

Comments
 (0)