diff --git a/src/AtomUI.Controls.DataGrid/Cell/DataGridCell.cs b/src/AtomUI.Controls.DataGrid/Cell/DataGridCell.cs index f4f8a80e7..97e530b0e 100644 --- a/src/AtomUI.Controls.DataGrid/Cell/DataGridCell.cs +++ b/src/AtomUI.Controls.DataGrid/Cell/DataGridCell.cs @@ -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; + } } \ No newline at end of file diff --git a/src/AtomUI.Controls.DataGrid/Column/DataGridColumnGroupHeader.cs b/src/AtomUI.Controls.DataGrid/Column/DataGridColumnGroupHeader.cs index 8a8f84ab4..e32001ac2 100644 --- a/src/AtomUI.Controls.DataGrid/Column/DataGridColumnGroupHeader.cs +++ b/src/AtomUI.Controls.DataGrid/Column/DataGridColumnGroupHeader.cs @@ -54,20 +54,12 @@ internal class DataGridColumnGroupHeader : TemplatedControl internal static readonly StyledProperty SizeTypeProperty = SizeTypeAwareControlProperty.SizeTypeProperty.AddOwner(); - internal static readonly StyledProperty BorderThicknessProperty = - Border.BorderThicknessProperty.AddOwner(); internal SizeType SizeType { get => GetValue(SizeTypeProperty); set => SetValue(SizeTypeProperty, value); } - - internal Thickness BorderThickness - { - get => GetValue(BorderThicknessProperty); - set => SetValue(BorderThicknessProperty, value); - } #endregion } \ No newline at end of file diff --git a/src/AtomUI.Controls.DataGrid/Column/DataGridColumnHeader.cs b/src/AtomUI.Controls.DataGrid/Column/DataGridColumnHeader.cs index 9fd2800c4..1fe23ef37 100644 --- a/src/AtomUI.Controls.DataGrid/Column/DataGridColumnHeader.cs +++ b/src/AtomUI.Controls.DataGrid/Column/DataGridColumnHeader.cs @@ -101,9 +101,6 @@ internal class DataGridColumnHeader : ContentControl internal static readonly StyledProperty SupportedDirectionsProperty = DataGridColumn.SupportedDirectionsProperty.AddOwner(); - internal static readonly StyledProperty BorderThicknessProperty = - Border.BorderThicknessProperty.AddOwner(); - 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; diff --git a/src/AtomUI.Controls.DataGrid/Column/DataGridHeaderViewItem.cs b/src/AtomUI.Controls.DataGrid/Column/DataGridHeaderViewItem.cs index 17841622c..61ef7a8b8 100644 --- a/src/AtomUI.Controls.DataGrid/Column/DataGridHeaderViewItem.cs +++ b/src/AtomUI.Controls.DataGrid/Column/DataGridHeaderViewItem.cs @@ -40,19 +40,11 @@ public class DataGridHeaderViewItem : HeaderedItemsControl #endregion #region 内部属性定义 - internal static readonly StyledProperty BorderThicknessProperty = - Border.BorderThicknessProperty.AddOwner(); internal static readonly DirectProperty EffectiveBorderThicknessProperty = AvaloniaProperty.RegisterDirect( nameof(EffectiveBorderThickness), o => o.EffectiveBorderThickness); - internal Thickness BorderThickness - { - get => GetValue(BorderThicknessProperty); - set => SetValue(BorderThicknessProperty, value); - } - internal Thickness EffectiveBorderThickness { get => _effectiveBorderThickness; diff --git a/src/AtomUI.Controls.DataGrid/DataGrid.Columns.cs b/src/AtomUI.Controls.DataGrid/DataGrid.Columns.cs index 2e3442458..7af9fdc4f 100644 --- a/src/AtomUI.Controls.DataGrid/DataGrid.Columns.cs +++ b/src/AtomUI.Controls.DataGrid/DataGrid.Columns.cs @@ -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) diff --git a/src/AtomUI.Controls.DataGrid/DataGrid.Privates.cs b/src/AtomUI.Controls.DataGrid/DataGrid.Privates.cs index 7484e0831..b38b2da7e 100644 --- a/src/AtomUI.Controls.DataGrid/DataGrid.Privates.cs +++ b/src/AtomUI.Controls.DataGrid/DataGrid.Privates.cs @@ -31,6 +31,19 @@ public partial class DataGrid internal const bool DefaultCanUserSortColumns = false; #region 内部属性定义 + + public static readonly DirectProperty IsGroupHeaderModeProperty = + AvaloniaProperty.RegisterDirect( + 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 RowGroupHeadersTable { get; private set; } diff --git a/src/AtomUI.Controls.DataGrid/DataGrid.Rows.cs b/src/AtomUI.Controls.DataGrid/DataGrid.Rows.cs index f3d7db62a..da2c4005f 100644 --- a/src/AtomUI.Controls.DataGrid/DataGrid.Rows.cs +++ b/src/AtomUI.Controls.DataGrid/DataGrid.Rows.cs @@ -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)); diff --git a/src/AtomUI.Controls.DataGrid/DataGrid.cs b/src/AtomUI.Controls.DataGrid/DataGrid.cs index 292b8e42f..17e66f5a1 100644 --- a/src/AtomUI.Controls.DataGrid/DataGrid.cs +++ b/src/AtomUI.Controls.DataGrid/DataGrid.cs @@ -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 GridLinesVisibilityProperty = - AvaloniaProperty.Register(nameof(GridLinesVisibility)); + AvaloniaProperty.Register(nameof(GridLinesVisibility), DataGridGridLinesVisibility.Horizontal); public static readonly StyledProperty HeadersVisibilityProperty = AvaloniaProperty.Register(nameof(HeadersVisibility)); - public static readonly StyledProperty HorizontalGridLinesBrushProperty = - AvaloniaProperty.Register(nameof(HorizontalGridLinesBrush)); - - public static readonly StyledProperty VerticalGridLinesBrushProperty = - AvaloniaProperty.Register(nameof(VerticalGridLinesBrush)); - public static readonly StyledProperty HorizontalScrollBarVisibilityProperty = AvaloniaProperty.Register(nameof(HorizontalScrollBarVisibility)); @@ -139,15 +131,9 @@ public partial class DataGrid : TemplatedControl, defaultValue: DefaultMinColumnWidth, validate: IsValidMinColumnWidth); - /// - /// Defines the property. - /// public static readonly AttachedProperty IsScrollInertiaEnabledProperty = ScrollViewer.IsScrollInertiaEnabledProperty.AddOwner(); - public static readonly StyledProperty RowBackgroundProperty = - AvaloniaProperty.Register(nameof(RowBackground)); - public static readonly StyledProperty RowHeightProperty = AvaloniaProperty.Register( nameof(RowHeight), @@ -190,10 +176,7 @@ public partial class DataGrid : TemplatedControl, public static readonly StyledProperty AutoGenerateColumnsProperty = AvaloniaProperty.Register(nameof(AutoGenerateColumns)); - - /// - /// Identifies the ItemsSource property. - /// + public static readonly StyledProperty ItemsSourceProperty = AvaloniaProperty.Register(nameof(ItemsSource)); @@ -310,24 +293,6 @@ public partial class DataGrid : TemplatedControl, set => SetValue(HeadersVisibilityProperty, value); } - /// - /// Gets or sets the that is used to paint grid lines separating rows. - /// - public IBrush? HorizontalGridLinesBrush - { - get => GetValue(HorizontalGridLinesBrushProperty); - set => SetValue(HorizontalGridLinesBrushProperty, value); - } - - /// - /// Gets or sets the that is used to paint grid lines separating columns. - /// - public IBrush? VerticalGridLinesBrush - { - get => GetValue(VerticalGridLinesBrushProperty); - set => SetValue(VerticalGridLinesBrushProperty, value); - } - /// /// Gets or sets a value that indicates how the horizontal scroll bar is displayed. /// @@ -394,15 +359,6 @@ public partial class DataGrid : TemplatedControl, set => SetValue(MinColumnWidthProperty, value); } - /// - /// Gets or sets the that is used to paint row backgrounds. - /// - public IBrush RowBackground - { - get => GetValue(RowBackgroundProperty); - set => SetValue(RowBackgroundProperty, value); - } - /// /// Gets or sets the standard height of rows in the control. /// @@ -822,14 +778,12 @@ public partial class DataGrid : TemplatedControl, FrozenColumnCountProperty.Changed.AddClassHandler((x, e) => x.HandleFrozenColumnCountChanged(e)); GridLinesVisibilityProperty.Changed.AddClassHandler((x, e) => x.HandleGridLinesVisibilityChanged(e)); HeadersVisibilityProperty.Changed.AddClassHandler((x, e) => x.HandleHeadersVisibilityChanged(e)); - HorizontalGridLinesBrushProperty.Changed.AddClassHandler((x, e) => x.HandleHorizontalGridLinesBrushChanged(e)); IsReadOnlyProperty.Changed.AddClassHandler((x, e) => x.HandleIsReadOnlyChanged(e)); MaxColumnWidthProperty.Changed.AddClassHandler((x, e) => x.HandleMaxColumnWidthChanged(e)); MinColumnWidthProperty.Changed.AddClassHandler((x, e) => x.HandleMinColumnWidthChanged(e)); RowHeightProperty.Changed.AddClassHandler((x, e) => x.HandleRowHeightChanged(e)); RowHeaderWidthProperty.Changed.AddClassHandler((x, e) => x.HandleRowHeaderWidthChanged(e)); SelectionModeProperty.Changed.AddClassHandler((x, e) => x.HandleSelectionModeChanged(e)); - VerticalGridLinesBrushProperty.Changed.AddClassHandler((x, e) => x.HandleVerticalGridLinesBrushChanged(e)); SelectedIndexProperty.Changed.AddClassHandler((x, e) => x.HandleSelectedIndexChanged(e)); SelectedItemProperty.Changed.AddClassHandler((x, e) => x.HandleSelectedItemChanged(e)); IsEnabledProperty.Changed.AddClassHandler((x, e) => x.HandleIsEnabledChanged(e)); @@ -1338,31 +1292,36 @@ public partial class DataGrid : TemplatedControl, _columnHeadersPresenter = e.NameScope.Find(DataGridTheme.ColumnHeadersPresenterPart); _groupHeaderView = e.NameScope.Find(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 sortedInternal = new List(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(ColumnsItemsInternal); + sortedInternal.Sort(new DisplayIndexComparer()); + foreach (DataGridColumn column in sortedInternal) + { + InsertDisplayedColumnHeader(column); + } + } } if (_rowsPresenter != null) diff --git a/src/AtomUI.Controls.DataGrid/Row/DataGridRow.Privates.cs b/src/AtomUI.Controls.DataGrid/Row/DataGridRow.Privates.cs index 319dca07e..767366cc2 100644 --- a/src/AtomUI.Controls.DataGrid/Row/DataGridRow.Privates.cs +++ b/src/AtomUI.Controls.DataGrid/Row/DataGridRow.Privates.cs @@ -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) diff --git a/src/AtomUI.Controls.DataGrid/Row/DataGridRow.cs b/src/AtomUI.Controls.DataGrid/Row/DataGridRow.cs index 0a02ec6be..83b11edd8 100644 --- a/src/AtomUI.Controls.DataGrid/Row/DataGridRow.cs +++ b/src/AtomUI.Controls.DataGrid/Row/DataGridRow.cs @@ -110,6 +110,19 @@ public partial class DataGridRow : TemplatedControl #endregion + #region 内部属性定义 + + internal static readonly StyledProperty IsMotionEnabledProperty + = MotionAwareControlProperty.IsMotionEnabledProperty.AddOwner(); + + internal bool IsMotionEnabled + { + get => GetValue(IsMotionEnabledProperty); + set => SetValue(IsMotionEnabledProperty, value); + } + + #endregion + static DataGridRow() { HeaderProperty.Changed.AddClassHandler((x, e) => x.HandleHeaderChanged(e)); diff --git a/src/AtomUI.Controls.DataGrid/Row/DataGridRowsPresenter.cs b/src/AtomUI.Controls.DataGrid/Row/DataGridRowsPresenter.cs index 0723c8f4a..e0d689f8a 100644 --- a/src/AtomUI.Controls.DataGrid/Row/DataGridRowsPresenter.cs +++ b/src/AtomUI.Controls.DataGrid/Row/DataGridRowsPresenter.cs @@ -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? 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); diff --git a/src/AtomUI.Controls.DataGrid/Theme/DataGridCellTheme.cs b/src/AtomUI.Controls.DataGrid/Theme/DataGridCellTheme.cs index 0feb3140f..2410e231c 100644 --- a/src/AtomUI.Controls.DataGrid/Theme/DataGridCellTheme.cs +++ b/src/AtomUI.Controls.DataGrid/Theme/DataGridCellTheme.cs @@ -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); + } } \ No newline at end of file diff --git a/src/AtomUI.Controls.DataGrid/Theme/DataGridRowTheme.cs b/src/AtomUI.Controls.DataGrid/Theme/DataGridRowTheme.cs index 5693c987f..59166d780 100644 --- a/src/AtomUI.Controls.DataGrid/Theme/DataGridRowTheme.cs +++ b/src/AtomUI.Controls.DataGrid/Theme/DataGridRowTheme.cs @@ -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(() => new Transitions() + { + AnimationUtils.CreateTransition(Border.BackgroundProperty, SharedTokenKey.MotionDurationSlow) + })); + isMotionEnabledStyle.Add(frameStyle); + } + commonStyle.Add(isMotionEnabledStyle); + + Add(commonStyle); + } } \ No newline at end of file diff --git a/src/AtomUI.Controls.DataGrid/Theme/DataGridTheme.cs b/src/AtomUI.Controls.DataGrid/Theme/DataGridTheme.cs index 50ed1ce19..b43b5e9a1 100644 --- a/src/AtomUI.Controls.DataGrid/Theme/DataGridTheme.cs +++ b/src/AtomUI.Controls.DataGrid/Theme/DataGridTheme.cs @@ -41,7 +41,7 @@ internal class DataGridTheme : BaseControlTheme { return new FuncControlTemplate((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 => 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 => 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 => 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);