mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-22 09:23:53 +08:00
Add DataGrid row animation
This commit is contained in:
@@ -10,12 +10,13 @@ using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Rendering;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
[TemplatePart(DataGridCellTheme.RightGridLinePart, typeof(Rectangle))]
|
||||
[PseudoClasses(StdPseudoClass.Selected, StdPseudoClass.Current, StdPseudoClass.Edited, StdPseudoClass.Invalid, StdPseudoClass.Focus)]
|
||||
public class DataGridCell : ContentControl
|
||||
public class DataGridCell : ContentControl, ICustomHitTest
|
||||
{
|
||||
#region 公共属性定义
|
||||
|
||||
@@ -201,10 +202,11 @@ public class DataGridCell : ContentControl
|
||||
{
|
||||
if (OwningGrid != null && _rightGridLine != null)
|
||||
{
|
||||
if (OwningGrid.VerticalGridLinesBrush != null && OwningGrid.VerticalGridLinesBrush != _rightGridLine.Fill)
|
||||
{
|
||||
_rightGridLine.Fill = OwningGrid.VerticalGridLinesBrush;
|
||||
}
|
||||
// TODO border 绘制
|
||||
// if (OwningGrid.VerticalGridLinesBrush != null && OwningGrid.VerticalGridLinesBrush != _rightGridLine.Fill)
|
||||
// {
|
||||
// _rightGridLine.Fill = OwningGrid.VerticalGridLinesBrush;
|
||||
// }
|
||||
|
||||
bool newVisibility =
|
||||
(OwningGrid.GridLinesVisibility == DataGridGridLinesVisibility.Vertical || OwningGrid.GridLinesVisibility == DataGridGridLinesVisibility.All)
|
||||
@@ -234,4 +236,9 @@ public class DataGridCell : ContentControl
|
||||
Classes.Replace(column.CellStyleClasses);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HitTest(Point point)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -54,20 +54,12 @@ internal class DataGridColumnGroupHeader : TemplatedControl
|
||||
internal static readonly StyledProperty<SizeType> SizeTypeProperty =
|
||||
SizeTypeAwareControlProperty.SizeTypeProperty.AddOwner<DataGridColumnGroupHeader>();
|
||||
|
||||
internal static readonly StyledProperty<Thickness> BorderThicknessProperty =
|
||||
Border.BorderThicknessProperty.AddOwner<DataGridColumnGroupHeader>();
|
||||
|
||||
internal SizeType SizeType
|
||||
{
|
||||
get => GetValue(SizeTypeProperty);
|
||||
set => SetValue(SizeTypeProperty, value);
|
||||
}
|
||||
|
||||
internal Thickness BorderThickness
|
||||
{
|
||||
get => GetValue(BorderThicknessProperty);
|
||||
set => SetValue(BorderThicknessProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -101,9 +101,6 @@ internal class DataGridColumnHeader : ContentControl
|
||||
internal static readonly StyledProperty<DataGridSupportedDirections> SupportedDirectionsProperty =
|
||||
DataGridColumn.SupportedDirectionsProperty.AddOwner<DataGridColumnHeader>();
|
||||
|
||||
internal static readonly StyledProperty<Thickness> BorderThicknessProperty =
|
||||
Border.BorderThicknessProperty.AddOwner<DataGridColumnHeader>();
|
||||
|
||||
private bool _isFirstVisible = false;
|
||||
internal bool IsFirstVisible
|
||||
{
|
||||
@@ -163,12 +160,6 @@ internal class DataGridColumnHeader : ContentControl
|
||||
set => SetValue(SupportedDirectionsProperty, value);
|
||||
}
|
||||
|
||||
internal Thickness BorderThickness
|
||||
{
|
||||
get => GetValue(BorderThicknessProperty);
|
||||
set => SetValue(BorderThicknessProperty, value);
|
||||
}
|
||||
|
||||
internal DataGridColumn? OwningColumn { get; set; }
|
||||
|
||||
internal DataGrid? OwningGrid => OwningColumn?.OwningGrid;
|
||||
|
||||
@@ -40,19 +40,11 @@ public class DataGridHeaderViewItem : HeaderedItemsControl
|
||||
#endregion
|
||||
|
||||
#region 内部属性定义
|
||||
internal static readonly StyledProperty<Thickness> BorderThicknessProperty =
|
||||
Border.BorderThicknessProperty.AddOwner<DataGridHeaderViewItem>();
|
||||
|
||||
internal static readonly DirectProperty<DataGridHeaderViewItem, Thickness> EffectiveBorderThicknessProperty =
|
||||
AvaloniaProperty.RegisterDirect<DataGridHeaderViewItem, Thickness>(
|
||||
nameof(EffectiveBorderThickness), o => o.EffectiveBorderThickness);
|
||||
|
||||
internal Thickness BorderThickness
|
||||
{
|
||||
get => GetValue(BorderThicknessProperty);
|
||||
set => SetValue(BorderThicknessProperty, value);
|
||||
}
|
||||
|
||||
internal Thickness EffectiveBorderThickness
|
||||
{
|
||||
get => _effectiveBorderThickness;
|
||||
|
||||
@@ -187,8 +187,9 @@ public partial class DataGrid
|
||||
|
||||
internal bool ColumnRequiresRightGridLine(DataGridColumn dataGridColumn, bool includeLastRightGridLineWhenPresent)
|
||||
{
|
||||
// TODO border 绘制
|
||||
return (GridLinesVisibility == DataGridGridLinesVisibility.Vertical || GridLinesVisibility == DataGridGridLinesVisibility.All) &&
|
||||
VerticalGridLinesBrush != null &&
|
||||
// VerticalGridLinesBrush != null &&
|
||||
(dataGridColumn != ColumnsInternal.LastVisibleColumn ||
|
||||
(includeLastRightGridLineWhenPresent &&
|
||||
ColumnsInternal.FillerColumn != null &&
|
||||
@@ -2027,6 +2028,8 @@ public partial class DataGrid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IsGroupHeaderMode = ColumnGroupsInternal.Count > 0;
|
||||
}
|
||||
|
||||
private void HandleColumnGroupItemChanged(object? sender, DataGridColumnGroupChangedArgs args)
|
||||
|
||||
@@ -31,6 +31,19 @@ public partial class DataGrid
|
||||
internal const bool DefaultCanUserSortColumns = false;
|
||||
|
||||
#region 内部属性定义
|
||||
|
||||
public static readonly DirectProperty<DataGrid, bool> IsGroupHeaderModeProperty =
|
||||
AvaloniaProperty.RegisterDirect<DataGrid, bool>(
|
||||
nameof(IsGroupHeaderMode),
|
||||
o => o.IsGroupHeaderMode,
|
||||
(o, v) => o.IsGroupHeaderMode = v);
|
||||
|
||||
public bool IsGroupHeaderMode
|
||||
{
|
||||
get => _isGroupHeaderMode;
|
||||
set => SetAndRaise(IsGroupHeaderModeProperty, ref _isGroupHeaderMode, value);
|
||||
}
|
||||
private bool _isGroupHeaderMode;
|
||||
|
||||
internal IndexToValueTable<DataGridRowGroupInfo> RowGroupHeadersTable { get; private set; }
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using AtomUI.Controls.Data;
|
||||
using AtomUI.Controls.Utils;
|
||||
using AtomUI.Data;
|
||||
using AtomUI.Utils;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
@@ -95,7 +96,7 @@ public partial class DataGrid
|
||||
|
||||
internal bool AreRowBottomGridLinesRequired =>
|
||||
(GridLinesVisibility == DataGridGridLinesVisibility.Horizontal ||
|
||||
GridLinesVisibility == DataGridGridLinesVisibility.All) && HorizontalGridLinesBrush != null;
|
||||
GridLinesVisibility == DataGridGridLinesVisibility.All); // && HorizontalGridLinesBrush != null;
|
||||
|
||||
internal int FirstVisibleSlot => (SlotCount > 0) ? GetNextVisibleSlot(-1) : -1;
|
||||
|
||||
@@ -1155,6 +1156,7 @@ public partial class DataGrid
|
||||
dataGridRow.Slot = slot;
|
||||
dataGridRow.OwningGrid = this;
|
||||
dataGridRow.DataContext = dataContext;
|
||||
BindUtils.RelayBind(this, IsMotionEnabledProperty, dataGridRow, DataGridRow.IsMotionEnabledProperty);
|
||||
|
||||
CompleteCellsCollection(dataGridRow);
|
||||
NotifyLoadingRow(new DataGridRowEventArgs(dataGridRow));
|
||||
|
||||
@@ -22,8 +22,6 @@ using Avalonia.Data;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Utilities;
|
||||
|
||||
@@ -100,17 +98,11 @@ public partial class DataGrid : TemplatedControl,
|
||||
validate: ValidateFrozenColumnCount);
|
||||
|
||||
public static readonly StyledProperty<DataGridGridLinesVisibility> GridLinesVisibilityProperty =
|
||||
AvaloniaProperty.Register<DataGrid, DataGridGridLinesVisibility>(nameof(GridLinesVisibility));
|
||||
AvaloniaProperty.Register<DataGrid, DataGridGridLinesVisibility>(nameof(GridLinesVisibility), DataGridGridLinesVisibility.Horizontal);
|
||||
|
||||
public static readonly StyledProperty<DataGridHeadersVisibility> HeadersVisibilityProperty =
|
||||
AvaloniaProperty.Register<DataGrid, DataGridHeadersVisibility>(nameof(HeadersVisibility));
|
||||
|
||||
public static readonly StyledProperty<IBrush?> HorizontalGridLinesBrushProperty =
|
||||
AvaloniaProperty.Register<DataGrid, IBrush?>(nameof(HorizontalGridLinesBrush));
|
||||
|
||||
public static readonly StyledProperty<IBrush?> VerticalGridLinesBrushProperty =
|
||||
AvaloniaProperty.Register<DataGrid, IBrush?>(nameof(VerticalGridLinesBrush));
|
||||
|
||||
public static readonly StyledProperty<ScrollBarVisibility> HorizontalScrollBarVisibilityProperty =
|
||||
AvaloniaProperty.Register<DataGrid, ScrollBarVisibility>(nameof(HorizontalScrollBarVisibility));
|
||||
|
||||
@@ -139,15 +131,9 @@ public partial class DataGrid : TemplatedControl,
|
||||
defaultValue: DefaultMinColumnWidth,
|
||||
validate: IsValidMinColumnWidth);
|
||||
|
||||
/// <summary>
|
||||
/// Defines the <see cref="IsScrollInertiaEnabled"/> property.
|
||||
/// </summary>
|
||||
public static readonly AttachedProperty<bool> IsScrollInertiaEnabledProperty =
|
||||
ScrollViewer.IsScrollInertiaEnabledProperty.AddOwner<DataGrid>();
|
||||
|
||||
public static readonly StyledProperty<IBrush> RowBackgroundProperty =
|
||||
AvaloniaProperty.Register<DataGrid, IBrush>(nameof(RowBackground));
|
||||
|
||||
public static readonly StyledProperty<double> RowHeightProperty =
|
||||
AvaloniaProperty.Register<DataGrid, double>(
|
||||
nameof(RowHeight),
|
||||
@@ -190,10 +176,7 @@ public partial class DataGrid : TemplatedControl,
|
||||
|
||||
public static readonly StyledProperty<bool> AutoGenerateColumnsProperty =
|
||||
AvaloniaProperty.Register<DataGrid, bool>(nameof(AutoGenerateColumns));
|
||||
|
||||
/// <summary>
|
||||
/// Identifies the ItemsSource property.
|
||||
/// </summary>
|
||||
|
||||
public static readonly StyledProperty<IEnumerable?> ItemsSourceProperty =
|
||||
AvaloniaProperty.Register<DataGrid, IEnumerable?>(nameof(ItemsSource));
|
||||
|
||||
@@ -310,24 +293,6 @@ public partial class DataGrid : TemplatedControl,
|
||||
set => SetValue(HeadersVisibilityProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="T:System.Windows.Media.Brush" /> that is used to paint grid lines separating rows.
|
||||
/// </summary>
|
||||
public IBrush? HorizontalGridLinesBrush
|
||||
{
|
||||
get => GetValue(HorizontalGridLinesBrushProperty);
|
||||
set => SetValue(HorizontalGridLinesBrushProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="T:System.Windows.Media.Brush" /> that is used to paint grid lines separating columns.
|
||||
/// </summary>
|
||||
public IBrush? VerticalGridLinesBrush
|
||||
{
|
||||
get => GetValue(VerticalGridLinesBrushProperty);
|
||||
set => SetValue(VerticalGridLinesBrushProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value that indicates how the horizontal scroll bar is displayed.
|
||||
/// </summary>
|
||||
@@ -394,15 +359,6 @@ public partial class DataGrid : TemplatedControl,
|
||||
set => SetValue(MinColumnWidthProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="T:System.Windows.Media.Brush" /> that is used to paint row backgrounds.
|
||||
/// </summary>
|
||||
public IBrush RowBackground
|
||||
{
|
||||
get => GetValue(RowBackgroundProperty);
|
||||
set => SetValue(RowBackgroundProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the standard height of rows in the control.
|
||||
/// </summary>
|
||||
@@ -822,14 +778,12 @@ public partial class DataGrid : TemplatedControl,
|
||||
FrozenColumnCountProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleFrozenColumnCountChanged(e));
|
||||
GridLinesVisibilityProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleGridLinesVisibilityChanged(e));
|
||||
HeadersVisibilityProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleHeadersVisibilityChanged(e));
|
||||
HorizontalGridLinesBrushProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleHorizontalGridLinesBrushChanged(e));
|
||||
IsReadOnlyProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleIsReadOnlyChanged(e));
|
||||
MaxColumnWidthProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleMaxColumnWidthChanged(e));
|
||||
MinColumnWidthProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleMinColumnWidthChanged(e));
|
||||
RowHeightProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleRowHeightChanged(e));
|
||||
RowHeaderWidthProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleRowHeaderWidthChanged(e));
|
||||
SelectionModeProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleSelectionModeChanged(e));
|
||||
VerticalGridLinesBrushProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleVerticalGridLinesBrushChanged(e));
|
||||
SelectedIndexProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleSelectedIndexChanged(e));
|
||||
SelectedItemProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleSelectedItemChanged(e));
|
||||
IsEnabledProperty.Changed.AddClassHandler<DataGrid>((x, e) => x.HandleIsEnabledChanged(e));
|
||||
@@ -1338,31 +1292,36 @@ public partial class DataGrid : TemplatedControl,
|
||||
_columnHeadersPresenter = e.NameScope.Find<DataGridColumnHeadersPresenter>(DataGridTheme.ColumnHeadersPresenterPart);
|
||||
_groupHeaderView = e.NameScope.Find<DataGridHeaderView>(DataGridTheme.ColumnHeaderViewPart);
|
||||
|
||||
if (_columnHeadersPresenter != null)
|
||||
if (ColumnGroups.Count > 0)
|
||||
{
|
||||
if (ColumnsInternal.FillerColumn != null)
|
||||
if (_groupHeaderView != null)
|
||||
{
|
||||
ColumnsInternal.FillerColumn.IsRepresented = false;
|
||||
}
|
||||
_columnHeadersPresenter.OwningGrid = this;
|
||||
if (ColumnsInternal.FillerColumn != null)
|
||||
{
|
||||
ColumnsInternal.FillerColumn.IsRepresented = false;
|
||||
}
|
||||
|
||||
// Columns were added before our Template was applied, add the ColumnHeaders now
|
||||
// List<DataGridColumn> sortedInternal = new List<DataGridColumn>(ColumnsItemsInternal);
|
||||
// sortedInternal.Sort(new DisplayIndexComparer());
|
||||
// foreach (DataGridColumn column in sortedInternal)
|
||||
// {
|
||||
// InsertDisplayedColumnHeader(column);
|
||||
// }
|
||||
BuildColumnGroupView();
|
||||
}
|
||||
}
|
||||
|
||||
if (_groupHeaderView != null)
|
||||
else
|
||||
{
|
||||
if (ColumnsInternal.FillerColumn != null)
|
||||
if (_columnHeadersPresenter != null)
|
||||
{
|
||||
ColumnsInternal.FillerColumn.IsRepresented = false;
|
||||
}
|
||||
if (ColumnsInternal.FillerColumn != null)
|
||||
{
|
||||
ColumnsInternal.FillerColumn.IsRepresented = false;
|
||||
}
|
||||
_columnHeadersPresenter.OwningGrid = this;
|
||||
|
||||
BuildColumnGroupView();
|
||||
// Columns were added before our Template was applied, add the ColumnHeaders now
|
||||
var sortedInternal = new List<DataGridColumn>(ColumnsItemsInternal);
|
||||
sortedInternal.Sort(new DisplayIndexComparer());
|
||||
foreach (DataGridColumn column in sortedInternal)
|
||||
{
|
||||
InsertDisplayedColumnHeader(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_rowsPresenter != null)
|
||||
|
||||
@@ -423,10 +423,7 @@ public partial class DataGridRow
|
||||
|
||||
internal void EnsureFillerVisibility()
|
||||
{
|
||||
if (_cellsElement != null)
|
||||
{
|
||||
_cellsElement.EnsureFillerVisibility();
|
||||
}
|
||||
_cellsElement?.EnsureFillerVisibility();
|
||||
}
|
||||
|
||||
internal void EnsureGridLines()
|
||||
@@ -443,7 +440,7 @@ public partial class DataGridRow
|
||||
{
|
||||
_bottomGridLine.IsVisible = newVisibility;
|
||||
}
|
||||
_bottomGridLine.Fill = OwningGrid.HorizontalGridLinesBrush;
|
||||
_bottomGridLine.Height = OwningGrid.BorderThickness.Left;
|
||||
}
|
||||
|
||||
foreach (DataGridCell cell in Cells)
|
||||
|
||||
@@ -110,6 +110,19 @@ public partial class DataGridRow : TemplatedControl
|
||||
|
||||
#endregion
|
||||
|
||||
#region 内部属性定义
|
||||
|
||||
internal static readonly StyledProperty<bool> IsMotionEnabledProperty
|
||||
= MotionAwareControlProperty.IsMotionEnabledProperty.AddOwner<DataGridRow>();
|
||||
|
||||
internal bool IsMotionEnabled
|
||||
{
|
||||
get => GetValue(IsMotionEnabledProperty);
|
||||
set => SetValue(IsMotionEnabledProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
static DataGridRow()
|
||||
{
|
||||
HeaderProperty.Changed.AddClassHandler<DataGridRow>((x, e) => x.HandleHeaderChanged(e));
|
||||
|
||||
@@ -26,11 +26,7 @@ public sealed class DataGridRowsPresenter : Panel, IChildIndexProvider
|
||||
AddHandler(Gestures.ScrollGestureEvent, OnScrollGesture);
|
||||
}
|
||||
|
||||
internal DataGrid? OwningGrid
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
internal DataGrid? OwningGrid { get; set; }
|
||||
|
||||
event EventHandler<ChildIndexChangedEventArgs>? IChildIndexProvider.ChildIndexChanged
|
||||
{
|
||||
@@ -77,10 +73,11 @@ public sealed class DataGridRowsPresenter : Panel, IChildIndexProvider
|
||||
return base.ArrangeOverride(finalSize);
|
||||
}
|
||||
Debug.Assert(OwningGrid.ColumnsInternal.FillerColumn is not null);
|
||||
var availableHeight = 0d;
|
||||
if (OwningGrid.RowsPresenterAvailableSize.HasValue)
|
||||
{
|
||||
// TODO 需要审查,是否可以删除
|
||||
var availableHeight = OwningGrid.RowsPresenterAvailableSize.Value.Height;
|
||||
availableHeight = OwningGrid.RowsPresenterAvailableSize.Value.Height;
|
||||
}
|
||||
|
||||
OwningGrid.HandleFillerColumnWidthNeeded(finalSize.Width);
|
||||
|
||||
@@ -89,7 +89,6 @@ internal class DataGridCellTheme : BaseControlTheme
|
||||
var rightGridLine = new Rectangle()
|
||||
{
|
||||
Name = RightGridLinePart,
|
||||
Width = 1,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
};
|
||||
Grid.SetColumn(contentPresenter, 1);
|
||||
@@ -115,20 +114,10 @@ internal class DataGridCellTheme : BaseControlTheme
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
Fill = Brushes.Transparent,
|
||||
IsHitTestVisible = false,
|
||||
StrokeThickness = 2
|
||||
StrokeThickness = 1
|
||||
};
|
||||
|
||||
var secondaryFocusVisual = new Rectangle()
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
Fill = Brushes.Transparent,
|
||||
IsHitTestVisible = false,
|
||||
StrokeThickness = 1
|
||||
};
|
||||
focusVisualLayout.Children.Add(primaryFocusVisual);
|
||||
focusVisualLayout.Children.Add(secondaryFocusVisual);
|
||||
|
||||
Grid.SetColumn(focusVisualLayout, 0);
|
||||
rootLayout.Children.Add(focusVisualLayout);
|
||||
}
|
||||
@@ -139,6 +128,29 @@ internal class DataGridCellTheme : BaseControlTheme
|
||||
commonStyle.Add(DataGridCell.HorizontalAlignmentProperty, HorizontalAlignment.Stretch);
|
||||
commonStyle.Add(DataGridCell.VerticalAlignmentProperty, VerticalAlignment.Stretch);
|
||||
commonStyle.Add(DataGridCell.FocusableProperty, false);
|
||||
|
||||
BuildSizeTypeStyle(commonStyle);
|
||||
Add(commonStyle);
|
||||
}
|
||||
|
||||
private void BuildSizeTypeStyle(Style commonStyle)
|
||||
{
|
||||
var largeStyle =
|
||||
new Style(selector => selector.Nesting().PropertyEquals(DataGridCell.SizeTypeProperty, SizeType.Large));
|
||||
largeStyle.Add(DataGridCell.PaddingProperty, DataGridTokenKey.TablePadding);
|
||||
largeStyle.Add(DataGridCell.FontSizeProperty, DataGridTokenKey.TableFontSize);
|
||||
commonStyle.Add(largeStyle);
|
||||
|
||||
var middleStyle =
|
||||
new Style(selector => selector.Nesting().PropertyEquals(DataGridCell.SizeTypeProperty, SizeType.Middle));
|
||||
middleStyle.Add(DataGridCell.PaddingProperty, DataGridTokenKey.TablePaddingMiddle);
|
||||
middleStyle.Add(DataGridCell.FontSizeProperty, DataGridTokenKey.TableFontSizeMiddle);
|
||||
commonStyle.Add(middleStyle);
|
||||
|
||||
var smallStyle =
|
||||
new Style(selector => selector.Nesting().PropertyEquals(DataGridCell.SizeTypeProperty, SizeType.Small));
|
||||
smallStyle.Add(DataGridCell.PaddingProperty, DataGridTokenKey.TablePaddingSmall);
|
||||
smallStyle.Add(DataGridCell.FontSizeProperty, DataGridTokenKey.TableFontSizeSmall);
|
||||
commonStyle.Add(smallStyle);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,27 @@
|
||||
using AtomUI.Controls.Utils;
|
||||
using AtomUI.Media;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Styling;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Styling;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
[ControlThemeProvider]
|
||||
internal class DataGridRowTheme : BaseControlTheme
|
||||
{
|
||||
public const string FramePart = "PART_Frame";
|
||||
public const string RowCellsFramePart = "PART_CellsFrame";
|
||||
public const string BottomGridLinePart = "PART_BottomGridLine";
|
||||
public const string CellsPresenterPart = "PART_CellsPresenter";
|
||||
public const string DetailsPresenterPart = "PART_DetailsPresenter";
|
||||
public const string FramePart = "PART_Frame";
|
||||
public const string RootLayoutPart = "PART_RootLayout";
|
||||
public const string RowHeaderPart = "PART_RowHeader";
|
||||
public const string RowBackgroundPart = "PART_RowBackground";
|
||||
public const string InvalidVisualElementPart = "PART_InvalidVisualElement";
|
||||
|
||||
public DataGridRowTheme() : base(typeof(DataGridRow))
|
||||
@@ -36,70 +40,73 @@ internal class DataGridRowTheme : BaseControlTheme
|
||||
var rootLayout = new DataGridFrozenGrid()
|
||||
{
|
||||
Name = RootLayoutPart,
|
||||
ColumnDefinitions = [
|
||||
new ColumnDefinition(GridLength.Auto),
|
||||
new ColumnDefinition(GridLength.Star),
|
||||
],
|
||||
RowDefinitions = [
|
||||
new RowDefinition(GridLength.Star),
|
||||
new RowDefinition(GridLength.Auto),
|
||||
new RowDefinition(GridLength.Auto),
|
||||
new RowDefinition(GridLength.Auto)
|
||||
],
|
||||
ColumnDefinitions = [
|
||||
new ColumnDefinition(GridLength.Auto),
|
||||
new ColumnDefinition(GridLength.Star)
|
||||
]
|
||||
};
|
||||
|
||||
var rowBackground = new Rectangle()
|
||||
var rowCellsFrame = new Border
|
||||
{
|
||||
Name = RowBackgroundPart,
|
||||
Name = RowCellsFramePart,
|
||||
};
|
||||
Grid.SetRow(rowBackground, 0);
|
||||
Grid.SetColumn(rowBackground, 0);
|
||||
Grid.SetColumnSpan(rowBackground, 2);
|
||||
Grid.SetRowSpan(rowBackground, 2);
|
||||
rootLayout.Children.Add(rowBackground);
|
||||
Grid.SetRow(rowCellsFrame, 0);
|
||||
Grid.SetColumn(rowCellsFrame, 0);
|
||||
Grid.SetColumnSpan(rowCellsFrame, 2);
|
||||
Grid.SetRowSpan(rowCellsFrame, 2);
|
||||
rootLayout.Children.Add(rowCellsFrame);
|
||||
|
||||
var invalidVisualElement = new Rectangle()
|
||||
var invalidVisualElement = new Rectangle
|
||||
{
|
||||
Name = InvalidVisualElementPart,
|
||||
Opacity = 0
|
||||
};
|
||||
Grid.SetRow(rowBackground, 0);
|
||||
Grid.SetColumn(rowBackground, 0);
|
||||
Grid.SetColumnSpan(rowBackground, 2);
|
||||
Grid.SetRow(invalidVisualElement, 0);
|
||||
Grid.SetColumn(invalidVisualElement, 0);
|
||||
Grid.SetColumnSpan(invalidVisualElement, 2);
|
||||
rootLayout.Children.Add(invalidVisualElement);
|
||||
|
||||
var rowHeader = new DataGridRowHeader()
|
||||
{
|
||||
Name = RowHeaderPart,
|
||||
};
|
||||
rowHeader.RegisterInNameScope(scope);
|
||||
Grid.SetRow(rowHeader, 0);
|
||||
Grid.SetColumn(rowHeader, 0);
|
||||
Grid.SetRowSpan(rowHeader, 3);
|
||||
DataGridFrozenGrid.SetIsFrozen(rowHeader, true);
|
||||
rootLayout.Children.Add(rowHeader);
|
||||
|
||||
var cellsPresenter = new DataGridCellsPresenter()
|
||||
var cellsPresenter = new DataGridCellsPresenter
|
||||
{
|
||||
Name = CellsPresenterPart,
|
||||
};
|
||||
cellsPresenter.RegisterInNameScope(scope);
|
||||
Grid.SetRow(cellsPresenter, 0);
|
||||
Grid.SetColumn(cellsPresenter, 1);
|
||||
DataGridFrozenGrid.SetIsFrozen(cellsPresenter, true);
|
||||
rootLayout.Children.Add(cellsPresenter);
|
||||
|
||||
var detailsPresenter = new DataGridDetailsPresenter()
|
||||
var detailsPresenter = new DataGridDetailsPresenter
|
||||
{
|
||||
Name = DetailsPresenterPart,
|
||||
};
|
||||
detailsPresenter.RegisterInNameScope(scope);
|
||||
Grid.SetRow(detailsPresenter, 1);
|
||||
Grid.SetColumn(detailsPresenter, 1);
|
||||
rootLayout.Children.Add(detailsPresenter);
|
||||
|
||||
var bottomGridLine = new Rectangle()
|
||||
var bottomGridLine = new Rectangle
|
||||
{
|
||||
Name = BottomGridLinePart,
|
||||
Height = 1,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch
|
||||
};
|
||||
bottomGridLine.RegisterInNameScope(scope);
|
||||
Grid.SetRow(bottomGridLine, 2);
|
||||
Grid.SetColumn(bottomGridLine, 1);
|
||||
rootLayout.Children.Add(bottomGridLine);
|
||||
@@ -108,4 +115,40 @@ internal class DataGridRowTheme : BaseControlTheme
|
||||
return frame;
|
||||
});
|
||||
}
|
||||
|
||||
protected override void BuildStyles()
|
||||
{
|
||||
var commonStyle = new Style(selector => selector.Nesting());
|
||||
commonStyle.Add(DataGridRow.FocusableProperty, false);
|
||||
var bottomGridLineStyle = new Style(selector => selector.Nesting().Template().Name(BottomGridLinePart));
|
||||
bottomGridLineStyle.Add(Rectangle.FillProperty, DataGridTokenKey.TableBorderColor);
|
||||
commonStyle.Add(bottomGridLineStyle);
|
||||
{
|
||||
var frameStyle = new Style(selector => selector.Nesting().Template().Name(FramePart));
|
||||
frameStyle.Add(Border.BackgroundProperty, DataGridTokenKey.TableBg);
|
||||
commonStyle.Add(frameStyle);
|
||||
}
|
||||
|
||||
var hoverStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver));
|
||||
{
|
||||
var frameStyle = new Style(selector => selector.Nesting().Template().Name(FramePart));
|
||||
frameStyle.Add(Border.BackgroundProperty, DataGridTokenKey.TableRowHoverBg);
|
||||
hoverStyle.Add(frameStyle);
|
||||
}
|
||||
commonStyle.Add(hoverStyle);
|
||||
|
||||
// 动画设置
|
||||
var isMotionEnabledStyle = new Style(selector => selector.Nesting().PropertyEquals(DataGridRow.IsMotionEnabledProperty, true));
|
||||
{
|
||||
var frameStyle = new Style(selector => selector.Nesting().Template().Name(FramePart));
|
||||
frameStyle.Add(Border.TransitionsProperty, new SetterValueFactory<Transitions>(() => new Transitions()
|
||||
{
|
||||
AnimationUtils.CreateTransition<SolidColorBrushTransition>(Border.BackgroundProperty, SharedTokenKey.MotionDurationSlow)
|
||||
}));
|
||||
isMotionEnabledStyle.Add(frameStyle);
|
||||
}
|
||||
commonStyle.Add(isMotionEnabledStyle);
|
||||
|
||||
Add(commonStyle);
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ internal class DataGridTheme : BaseControlTheme
|
||||
{
|
||||
return new FuncControlTemplate<DataGrid>((dataGrid, scope) =>
|
||||
{
|
||||
var frame = new Border()
|
||||
var frame = new Border
|
||||
{
|
||||
Name = FramePart
|
||||
};
|
||||
@@ -135,12 +135,14 @@ internal class DataGridTheme : BaseControlTheme
|
||||
|
||||
private void BuildHeader(Grid rootLayout, INameScope scope, DataGrid dataGrid)
|
||||
{
|
||||
// TODO 这里需要考虑合并
|
||||
var columnHeaderView = new DataGridHeaderView(dataGrid)
|
||||
{
|
||||
Name = ColumnHeaderViewPart,
|
||||
ClipToBounds = true
|
||||
};
|
||||
CreateTemplateParentBinding(columnHeaderView, Border.CornerRadiusProperty, DataGrid.CornerRadiusProperty, BindingMode.Default,
|
||||
CreateTemplateParentBinding(columnHeaderView, DataGridHeaderView.IsVisibleProperty, DataGrid.IsGroupHeaderModeProperty);
|
||||
CreateTemplateParentBinding(columnHeaderView, DataGridHeaderView.CornerRadiusProperty, DataGrid.CornerRadiusProperty, BindingMode.Default,
|
||||
new FuncValueConverter<CornerRadius, CornerRadius>(cornerRadius => new CornerRadius(cornerRadius.TopLeft, cornerRadius.TopRight, 0, 0)));
|
||||
columnHeaderView.RegisterInNameScope(scope);
|
||||
Grid.SetRow(columnHeaderView, 0);
|
||||
@@ -148,23 +150,25 @@ internal class DataGridTheme : BaseControlTheme
|
||||
Grid.SetColumnSpan(columnHeaderView, 2);
|
||||
rootLayout.Children.Add(columnHeaderView);
|
||||
|
||||
// var headerFrame = new Border
|
||||
// {
|
||||
// Name = ColumnHeadersPresenterFramePart,
|
||||
// ClipToBounds = true
|
||||
// };
|
||||
// CreateTemplateParentBinding(headerFrame, Border.CornerRadiusProperty, DataGrid.CornerRadiusProperty, BindingMode.Default,
|
||||
// new FuncValueConverter<CornerRadius, CornerRadius>(cornerRadius => new CornerRadius(cornerRadius.TopLeft, cornerRadius.TopRight, 0, 0)));
|
||||
// var columnHeadersPresenter = new DataGridColumnHeadersPresenter()
|
||||
// {
|
||||
// Name = ColumnHeadersPresenterPart,
|
||||
// };
|
||||
// headerFrame.Child = columnHeadersPresenter;
|
||||
// columnHeadersPresenter.RegisterInNameScope(scope);
|
||||
// Grid.SetRow(headerFrame, 0);
|
||||
// Grid.SetColumn(headerFrame, 1);
|
||||
// Grid.SetColumnSpan(headerFrame, 2);
|
||||
// rootLayout.Children.Add(headerFrame);
|
||||
var headerFrame = new Border
|
||||
{
|
||||
Name = ColumnHeadersPresenterFramePart,
|
||||
ClipToBounds = true
|
||||
};
|
||||
CreateTemplateParentBinding(headerFrame, Border.IsVisibleProperty, DataGrid.IsGroupHeaderModeProperty, BindingMode.Default,
|
||||
BoolConverters.Not);
|
||||
CreateTemplateParentBinding(headerFrame, Border.CornerRadiusProperty, DataGrid.CornerRadiusProperty, BindingMode.Default,
|
||||
new FuncValueConverter<CornerRadius, CornerRadius>(cornerRadius => new CornerRadius(cornerRadius.TopLeft, cornerRadius.TopRight, 0, 0)));
|
||||
var columnHeadersPresenter = new DataGridColumnHeadersPresenter()
|
||||
{
|
||||
Name = ColumnHeadersPresenterPart,
|
||||
};
|
||||
headerFrame.Child = columnHeadersPresenter;
|
||||
columnHeadersPresenter.RegisterInNameScope(scope);
|
||||
Grid.SetRow(headerFrame, 0);
|
||||
Grid.SetColumn(headerFrame, 1);
|
||||
Grid.SetColumnSpan(headerFrame, 2);
|
||||
rootLayout.Children.Add(headerFrame);
|
||||
|
||||
var columnHeadersAndRowsSeparator = new Rectangle()
|
||||
{
|
||||
@@ -221,8 +225,6 @@ internal class DataGridTheme : BaseControlTheme
|
||||
commonStyle.Add(DataGrid.SelectionModeProperty, DataGridSelectionMode.Extended);
|
||||
commonStyle.Add(DataGrid.FocusAdornerProperty, null);
|
||||
commonStyle.Add(DataGrid.CornerRadiusProperty, DataGridTokenKey.TableRadius);
|
||||
commonStyle.Add(DataGrid.HorizontalGridLinesBrushProperty, DataGridTokenKey.TableBorderColor);
|
||||
commonStyle.Add(DataGrid.VerticalGridLinesBrushProperty, DataGridTokenKey.TableBorderColor);
|
||||
|
||||
var columnHeadersAndRowsSeparatorStyle = new Style(selector => selector.Nesting().Template().Name(ColumnHeadersAndRowsSeparatorPart));
|
||||
columnHeadersAndRowsSeparatorStyle.Add(Rectangle.FillProperty, DataGridTokenKey.TableBorderColor);
|
||||
|
||||
Reference in New Issue
Block a user