Browse Source

Merge branch 'master' into refactor/controltemplate-detach

pull/9500/head
Steven Kirk 3 years ago
committed by GitHub
parent
commit
88f9eb949d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 0
      .ncrunch/Avalonia.Benchmarks.v3.ncrunchproject
  2. 0
      .ncrunch/Avalonia.Browser.Blazor.v3.ncrunchproject
  3. 0
      .ncrunch/Avalonia.Browser.v3.ncrunchproject
  4. 0
      .ncrunch/Avalonia.Designer.HostApp.v3.ncrunchproject
  5. 5
      .ncrunch/Avalonia.Themes.Fluent.net6.0.v3.ncrunchproject
  6. 5
      .ncrunch/Avalonia.Themes.Fluent.netstandard2.0.v3.ncrunchproject
  7. 5
      .ncrunch/Avalonia.Themes.Simple.net6.0.v3.ncrunchproject
  8. 5
      .ncrunch/Avalonia.Themes.Simple.netstandard2.0.v3.ncrunchproject
  9. 5
      .ncrunch/ControlCatalog.Browser.Blazor.v3.ncrunchproject
  10. 5
      .ncrunch/ControlCatalog.Browser.v3.ncrunchproject
  11. 5
      .ncrunch/MobileSandbox.v3.ncrunchproject
  12. 51
      samples/ControlCatalog/Pages/DataGridPage.xaml
  13. 89
      src/Avalonia.Controls.DataGrid/DataGrid.cs
  14. 39
      src/Avalonia.Controls.DataGrid/DataGridColumn.cs
  15. 15
      src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs
  16. 25
      src/Avalonia.Controls.DataGrid/DataGridRow.cs
  17. 14
      src/Avalonia.Controls.DataGrid/DataGridRowGroupHeader.cs
  18. 72
      src/Avalonia.Controls.DataGrid/DataGridRows.cs
  19. 7
      src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml
  20. 5
      src/Avalonia.Controls.DataGrid/Themes/Simple.xaml

0
.ncrunch/Avalonia.Web.Blazor.v3.ncrunchproject → .ncrunch/Avalonia.Benchmarks.v3.ncrunchproject

0
.ncrunch/Avalonia.Web.v3.ncrunchproject → .ncrunch/Avalonia.Browser.Blazor.v3.ncrunchproject

0
.ncrunch/ControlCatalog.Blazor.Web.v3.ncrunchproject → .ncrunch/Avalonia.Browser.v3.ncrunchproject

0
.ncrunch/ControlCatalog.Web.v3.ncrunchproject → .ncrunch/Avalonia.Designer.HostApp.v3.ncrunchproject

5
.ncrunch/Avalonia.Themes.Fluent.net6.0.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<InstrumentOutputAssembly>False</InstrumentOutputAssembly>
</Settings>
</ProjectConfiguration>

5
.ncrunch/Avalonia.Themes.Fluent.netstandard2.0.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<InstrumentOutputAssembly>False</InstrumentOutputAssembly>
</Settings>
</ProjectConfiguration>

5
.ncrunch/Avalonia.Themes.Simple.net6.0.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<InstrumentOutputAssembly>False</InstrumentOutputAssembly>
</Settings>
</ProjectConfiguration>

5
.ncrunch/Avalonia.Themes.Simple.netstandard2.0.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<InstrumentOutputAssembly>False</InstrumentOutputAssembly>
</Settings>
</ProjectConfiguration>

5
.ncrunch/ControlCatalog.Browser.Blazor.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
</Settings>
</ProjectConfiguration>

5
.ncrunch/ControlCatalog.Browser.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
</Settings>
</ProjectConfiguration>

5
.ncrunch/MobileSandbox.v3.ncrunchproject

@ -0,0 +1,5 @@
<ProjectConfiguration>
<Settings>
<IgnoreThisComponentCompletely>True</IgnoreThisComponentCompletely>
</Settings>
</ProjectConfiguration>

51
samples/ControlCatalog/Pages/DataGridPage.xaml

@ -14,22 +14,6 @@
<Setter Property="Background" Value="{Binding Path=GDP, Mode=OneWay, Converter={StaticResource GDPConverter}}" />
</ControlTheme>
</UserControl.Resources>
<UserControl.Styles>
<Style Selector="DataGridColumnHeader:nth-last-child(1)">
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style Selector="DataGridCell:nth-last-child(1)">
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style Selector="DataGrid#dataGridGrouping DataGridRow:nth-child(5n+3)">
<Setter Property="Foreground" Value="Red" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style Selector="DataGrid#dataGridGrouping DataGridRow:nth-last-child(5n+1)">
<Setter Property="Foreground" Value="Blue" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
</UserControl.Styles>
<Grid RowDefinitions="Auto,Auto,*">
<StackPanel Orientation="Vertical" Spacing="4" Grid.Row="0">
<TextBlock Classes="h2">A control for displaying and interacting with a data source.</TextBlock>
@ -45,8 +29,7 @@
<CheckBox x:Name="ShowGDP" IsChecked="True" Content="Toggle GDP Column Visibility"
DockPanel.Dock="Top"/>
<DataGrid Name="dataGrid1" Margin="12" CanUserResizeColumns="True" CanUserReorderColumns="True" CanUserSortColumns="True" HeadersVisibility="All"
RowBackground="#1000"
AlternatingRowBackground="#1fff">
RowBackground="#1000">
<DataGrid.Columns>
<!-- Using HeaderTemplate -->
<DataGridTextColumn Header="Country" HeaderTemplate="{StaticResource Demo.DataTemplates.CountryHeader}" Binding="{Binding Name}" Width="6*" x:DataType="local:Country" />
@ -59,6 +42,24 @@
IsVisible="{Binding #ShowGDP.IsChecked}"
x:DataType="local:Country" />
</DataGrid.Columns>
<DataGrid.CellTheme>
<ControlTheme TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
<ControlTheme.Children>
<Style Selector="^:nth-child(1)">
<Setter Property="FontWeight" Value="Bold" />
</Style>
</ControlTheme.Children>
</ControlTheme>
</DataGrid.CellTheme>
<DataGrid.ColumnHeaderTheme>
<ControlTheme TargetType="DataGridColumnHeader" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
<ControlTheme.Children>
<Style Selector="^:nth-child(1)">
<Setter Property="FontWeight" Value="Bold" />
</Style>
</ControlTheme.Children>
</ControlTheme>
</DataGrid.ColumnHeaderTheme>
</DataGrid>
</DockPanel>
</TabItem>
@ -71,6 +72,20 @@
<DataGridTextColumn DisplayIndex="2" Header="Area" Binding="{Binding Area}" Width="3*" x:DataType="local:Country" />
<DataGridTextColumn Header="GDP" Binding="{Binding GDP}" Width="3*" x:DataType="local:Country" />
</DataGrid.Columns>
<DataGrid.RowTheme>
<ControlTheme TargetType="DataGridRow" BasedOn="{StaticResource {x:Type DataGridRow}}">
<ControlTheme.Children>
<Style Selector="^:nth-child(5n+3)">
<Setter Property="Foreground" Value="Red" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
<Style Selector="^:nth-last-child(5n+1)">
<Setter Property="Foreground" Value="Blue" />
<Setter Property="FontWeight" Value="Bold" />
</Style>
</ControlTheme.Children>
</ControlTheme>
</DataGrid.RowTheme>
</DataGrid>
</TabItem>
<TabItem x:Name="EditableTab" Header="Editable">

89
src/Avalonia.Controls.DataGrid/DataGrid.cs

@ -26,6 +26,7 @@ using Avalonia.Controls.Utils;
using Avalonia.Layout;
using Avalonia.Controls.Metadata;
using Avalonia.Input.GestureRecognizers;
using Avalonia.Styling;
namespace Avalonia.Controls
{
@ -238,29 +239,72 @@ namespace Avalonia.Controls
AvaloniaProperty.Register<DataGrid, DataGridLength>(nameof(ColumnWidth), defaultValue: DataGridLength.Auto);
/// <summary>
/// Gets or sets the standard width or automatic sizing mode of columns in the control.
/// Identifies the <see cref="RowTheme"/> dependency property.
/// </summary>
public DataGridLength ColumnWidth
public static readonly StyledProperty<ControlTheme> RowThemeProperty =
AvaloniaProperty.Register<DataGrid, ControlTheme>(nameof(RowTheme));
/// <summary>
/// Gets or sets the theme applied to all rows.
/// </summary>
public ControlTheme RowTheme
{
get { return GetValue(ColumnWidthProperty); }
set { SetValue(ColumnWidthProperty, value); }
get { return GetValue(RowThemeProperty); }
set { SetValue(RowThemeProperty, value); }
}
public static readonly StyledProperty<IBrush> AlternatingRowBackgroundProperty =
AvaloniaProperty.Register<DataGrid, IBrush>(nameof(AlternatingRowBackground));
/// <summary>
/// Identifies the <see cref="CellTheme"/> dependency property.
/// </summary>
public static readonly StyledProperty<ControlTheme> CellThemeProperty =
AvaloniaProperty.Register<DataGrid, ControlTheme>(nameof(CellTheme));
/// <summary>
/// Gets or sets the <see cref="T:System.Windows.Media.Brush" /> that is used to paint the background of odd-numbered rows.
/// Gets or sets the theme applied to all cells.
/// </summary>
/// <returns>
/// The brush that is used to paint the background of odd-numbered rows. The default is a
/// <see cref="T:System.Windows.Media.SolidColorBrush" /> with a
/// <see cref="P:System.Windows.Media.SolidColorBrush.Color" /> value of white (ARGB value #00FFFFFF).
/// </returns>
public IBrush AlternatingRowBackground
public ControlTheme CellTheme
{
get { return GetValue(CellThemeProperty); }
set { SetValue(CellThemeProperty, value); }
}
/// <summary>
/// Identifies the <see cref="ColumnHeaderTheme"/> dependency property.
/// </summary>
public static readonly StyledProperty<ControlTheme> ColumnHeaderThemeProperty =
AvaloniaProperty.Register<DataGrid, ControlTheme>(nameof(ColumnHeaderTheme));
/// <summary>
/// Gets or sets the theme applied to all column headers.
/// </summary>
public ControlTheme ColumnHeaderTheme
{
get { return GetValue(ColumnHeaderThemeProperty); }
set { SetValue(ColumnHeaderThemeProperty, value); }
}
/// <summary>
/// Identifies the <see cref="RowGroupTheme"/> dependency property.
/// </summary>
public static readonly StyledProperty<ControlTheme> RowGroupThemeProperty =
AvaloniaProperty.Register<DataGrid, ControlTheme>(nameof(RowGroupTheme));
/// <summary>
/// Gets or sets the theme applied to all row groups.
/// </summary>
public ControlTheme RowGroupTheme
{
get { return GetValue(AlternatingRowBackgroundProperty); }
set { SetValue(AlternatingRowBackgroundProperty, value); }
get { return GetValue(RowGroupThemeProperty); }
set { SetValue(RowGroupThemeProperty, value); }
}
/// <summary>
/// Gets or sets the standard width or automatic sizing mode of columns in the control.
/// </summary>
public DataGridLength ColumnWidth
{
get { return GetValue(ColumnWidthProperty); }
set { SetValue(ColumnWidthProperty, value); }
}
public static readonly StyledProperty<int> FrozenColumnCountProperty =
@ -2058,7 +2102,7 @@ namespace Avalonia.Controls
forceHorizontalScroll: true);
}
}
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
@ -2167,7 +2211,7 @@ namespace Avalonia.Controls
return desiredSize;
}
/// <inheritdoc/>
protected override void OnDataContextBeginUpdate()
{
@ -2183,7 +2227,7 @@ namespace Avalonia.Controls
NotifyDataContextPropertyForAllRowCells(GetAllRows(), false);
}
/// <summary>
/// Raises the BeginningEdit event.
/// </summary>
@ -3242,7 +3286,6 @@ namespace Avalonia.Controls
}
}
//TODO Styles
private void AddNewCellPrivate(DataGridRow row, DataGridColumn column)
{
DataGridCell newCell = new DataGridCell();
@ -3255,8 +3298,11 @@ namespace Avalonia.Controls
{
newCell.OwningColumn = column;
newCell.IsVisible = column.IsVisible;
if (row.OwningGrid.CellTheme is {} cellTheme)
{
newCell.SetValue(ThemeProperty, cellTheme, BindingPriority.TemplatedParent);
}
}
//newCell.EnsureStyle(null);
row.Cells.Insert(column.Index, newCell);
}
@ -4537,7 +4583,6 @@ namespace Avalonia.Controls
FlushCurrentCellChanged();
}
//TODO Styles
private void PopulateCellContent(bool isCellEdited,
DataGridColumn dataGridColumn,
DataGridRow dataGridRow,
@ -4575,7 +4620,7 @@ namespace Avalonia.Controls
dataGridCell.Content = element;
}
}
private void PreparingCellForEditPrivate(Control editingElement)

39
src/Avalonia.Controls.DataGrid/DataGridColumn.cs

@ -231,7 +231,7 @@ namespace Avalonia.Controls
}
/// <summary>
/// Gets or sets a value that indicates whether the user can change the column display position by
/// Gets or sets a value that indicates whether the user can change the column display position by
/// dragging the column header.
/// </summary>
/// <returns>
@ -260,15 +260,15 @@ namespace Avalonia.Controls
/// </returns>
public bool CanUserResize
{
get
get
{
return
CanUserResizeInternal ??
OwningGrid?.CanUserResizeColumns ??
DataGrid.DATAGRID_defaultCanUserResizeColumns;
}
set
{
set
{
CanUserResizeInternal = value;
OwningGrid?.OnColumnCanUserResizeChanged(this);
}
@ -321,16 +321,16 @@ namespace Avalonia.Controls
/// </returns>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// When setting this property, the specified value is less than -1 or equal to <see cref="F:System.Int32.MaxValue" />.
///
///
/// -or-
///
///
/// When setting this property on a column in a <see cref="T:Avalonia.Controls.DataGrid" />, the specified value is less than zero or greater than or equal to the number of columns in the <see cref="T:Avalonia.Controls.DataGrid" />.
/// </exception>
/// <exception cref="T:System.InvalidOperationException">
/// When setting this property, the <see cref="T:Avalonia.Controls.DataGrid" /> is already making <see cref="P:Avalonia.Controls.DataGridColumn.DisplayIndex" /> adjustments. For example, this exception is thrown when you attempt to set <see cref="P:Avalonia.Controls.DataGridColumn.DisplayIndex" /> in a <see cref="E:Avalonia.Controls.DataGrid.ColumnDisplayIndexChanged" /> event handler.
///
///
/// -or-
///
///
/// When setting this property, the specified value would result in a frozen column being displayed in the range of unfrozen columns, or an unfrozen column being displayed in the range of frozen columns.
/// </exception>
public int DisplayIndex
@ -401,7 +401,7 @@ namespace Avalonia.Controls
}
}
}
/// <summary>
/// Backing field for CellTheme property.
/// </summary>
@ -412,7 +412,7 @@ namespace Avalonia.Controls
(o, v) => o.CellTheme = v);
/// <summary>
/// Gets or sets the <see cref="DataGridColumnHeader"/> cell theme.
/// Gets or sets the <see cref="DataGridColumnHeader"/> cell theme.
/// </summary>
public ControlTheme CellTheme
{
@ -430,14 +430,14 @@ namespace Avalonia.Controls
(o, v) => o.Header = v);
/// <summary>
/// Gets or sets the <see cref="DataGridColumnHeader"/> content
/// Gets or sets the <see cref="DataGridColumnHeader"/> content
/// </summary>
public object Header
{
get { return _header; }
set { SetAndRaise(HeaderProperty, ref _header, value); }
}
/// <summary>
/// Backing field for Header property
/// </summary>
@ -455,7 +455,7 @@ namespace Avalonia.Controls
get { return _headerTemplate; }
set { SetAndRaise(HeaderTemplateProperty, ref _headerTemplate, value); }
}
public bool IsAutoGenerated
{
get;
@ -750,7 +750,7 @@ namespace Avalonia.Controls
protected abstract IControl GenerateEditingElement(DataGridCell cell, object dataItem, out ICellEditBinding binding);
/// <summary>
/// When overridden in a derived class, gets a read-only element that is bound to the column's
/// When overridden in a derived class, gets a read-only element that is bound to the column's
/// <see cref="P:Avalonia.Controls.DataGridBoundColumn.Binding" /> property value.
/// </summary>
/// <param name="cell">
@ -765,7 +765,7 @@ namespace Avalonia.Controls
protected abstract IControl GenerateElement(DataGridCell cell, object dataItem);
/// <summary>
/// Called by a specific column type when one of its properties changed,
/// Called by a specific column type when one of its properties changed,
/// and its current cells need to be updated.
/// </summary>
/// <param name="propertyName">Indicates which property changed and caused this call</param>
@ -882,9 +882,8 @@ namespace Avalonia.Controls
{
LayoutRoundedWidth = ActualWidth;
}
}
}
//TODO Styles
internal virtual DataGridColumnHeader CreateHeader()
{
var result = new DataGridColumnHeader
@ -893,8 +892,10 @@ namespace Avalonia.Controls
};
result[!ContentControl.ContentProperty] = this[!HeaderProperty];
result[!ContentControl.ContentTemplateProperty] = this[!HeaderTemplateProperty];
//result.EnsureStyle(null);
if (OwningGrid.ColumnHeaderTheme is {} columnTheme)
{
result.SetValue(StyledElement.ThemeProperty, columnTheme, BindingPriority.TemplatedParent);
}
return result;
}

15
src/Avalonia.Controls.DataGrid/DataGridColumnHeader.cs

@ -76,7 +76,7 @@ namespace Avalonia.Controls
}
/// <summary>
/// Initializes a new instance of the <see cref="T:Avalonia.Controls.Primitives.DataGridColumnHeader" /> class.
/// Initializes a new instance of the <see cref="T:Avalonia.Controls.Primitives.DataGridColumnHeader" /> class.
/// </summary>
//TODO Implement
public DataGridColumnHeader()
@ -267,7 +267,7 @@ namespace Avalonia.Controls
else
{
newSort = sort;
}
}
// changing direction should not affect sort order, so we replace this column's
// sort description instead of just adding it to the end of the collection
@ -603,7 +603,7 @@ namespace Avalonia.Controls
}
/// <summary>
/// Returns true if the mouse is
/// Returns true if the mouse is
/// - to the left of the element, or within the left half of the element
/// and
/// - within the vertical range of the element, or ignoreVertical == true
@ -663,16 +663,19 @@ namespace Avalonia.Controls
IsMouseOver = false;
}
//TODO Styles DragIndicator
private void OnMouseMove_BeginReorder(Point mousePosition)
{
DataGridColumnHeader dragIndicator = new DataGridColumnHeader
var dragIndicator = new DataGridColumnHeader
{
OwningColumn = OwningColumn,
IsEnabled = false,
Content = Content,
ContentTemplate = ContentTemplate
};
if (OwningGrid.ColumnHeaderTheme is {} columnHeaderTheme)
{
dragIndicator.SetValue(ThemeProperty, columnHeaderTheme, BindingPriority.TemplatedParent);
}
dragIndicator.PseudoClasses.Add(":dragIndicator");
@ -720,7 +723,7 @@ namespace Avalonia.Controls
{
return;
}
//handle entry into reorder mode
if (_dragMode == DragMode.MouseDown && _dragColumn == null && _lastMousePositionHeaders != null && (distanceFromRight > DATAGRIDCOLUMNHEADER_resizeRegionWidth && distanceFromLeft > DATAGRIDCOLUMNHEADER_resizeRegionWidth))
{

25
src/Avalonia.Controls.DataGrid/DataGridRow.cs

@ -89,7 +89,7 @@ namespace Avalonia.Controls
o => o.IsValid);
/// <summary>
/// Gets a value that indicates whether the data in a row is valid.
/// Gets a value that indicates whether the data in a row is valid.
/// </summary>
public bool IsValid
{
@ -130,7 +130,7 @@ namespace Avalonia.Controls
}
/// <summary>
/// Initializes a new instance of the <see cref="T:Avalonia.Controls.DataGridRow" /> class.
/// Initializes a new instance of the <see cref="T:Avalonia.Controls.DataGridRow" /> class.
/// </summary>
public DataGridRow()
{
@ -240,7 +240,6 @@ namespace Avalonia.Controls
private set;
}
//TODO Styles
internal DataGridCell FillerCell
{
get
@ -252,7 +251,10 @@ namespace Avalonia.Controls
IsVisible = false,
OwningRow = this
};
//_fillerCell.EnsureStyle(null);
if (OwningGrid.CellTheme is {} cellTheme)
{
_fillerCell.SetValue(ThemeProperty, cellTheme, BindingPriority.TemplatedParent);
}
if (_cellsElement != null)
{
_cellsElement.Children.Add(_fillerCell);
@ -506,7 +508,7 @@ namespace Avalonia.Controls
}
/// <summary>
/// Measures the children of a <see cref="T:Avalonia.Controls.DataGridRow" /> to
/// Measures the children of a <see cref="T:Avalonia.Controls.DataGridRow" /> to
/// prepare for arranging them during the <see cref="M:System.Windows.FrameworkElement.ArrangeOverride(System.Windows.Size)" /> pass.
/// </summary>
/// <param name="availableSize">
@ -709,8 +711,6 @@ namespace Avalonia.Controls
}
}
// Set the proper style for the Header by walking up the Style hierarchy
//TODO Styles
internal void EnsureHeaderStyleAndVisibility(Styling.Style previousStyle)
{
if (_headerElement != null && OwningGrid != null)
@ -785,7 +785,7 @@ namespace Avalonia.Controls
OwningGrid?.OnRowDetailsChanged();
}
// Returns the actual template that should be sued for Details: either explicity set on this row
// Returns the actual template that should be sued for Details: either explicity set on this row
// or inherited from the DataGrid
private IDataTemplate ActualDetailsTemplate
{
@ -890,7 +890,7 @@ namespace Avalonia.Controls
//TODO Cleanup
double? _previousDetailsHeight = null;
//TODO Animation
//TODO Animation
private void DetailsContent_HeightChanged(double newValue)
{
if (_previousDetailsHeight.HasValue)
@ -907,7 +907,7 @@ namespace Avalonia.Controls
_detailsElement.ContentHeight = newValue;
// Calling this when details are not visible invalidates during layout when we have no work
// Calling this when details are not visible invalidates during layout when we have no work
// to do. In certain scenarios, this could cause a layout cycle
OnRowDetailsChanged();
}
@ -1060,7 +1060,7 @@ namespace Avalonia.Controls
}
}
}
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
@ -1084,7 +1084,4 @@ namespace Avalonia.Controls
}
}
//TODO Styles
}

14
src/Avalonia.Controls.DataGrid/DataGridRowGroupHeader.cs

@ -53,7 +53,7 @@ namespace Avalonia.Controls
AvaloniaProperty.Register<DataGridRowGroupHeader, string>(nameof(PropertyName));
/// <summary>
/// Gets or sets the name of the property that this <see cref="T:Avalonia.Controls.DataGrid" /> row is bound to.
/// Gets or sets the name of the property that this <see cref="T:Avalonia.Controls.DataGrid" /> row is bound to.
/// </summary>
public string PropertyName
{
@ -85,8 +85,8 @@ namespace Avalonia.Controls
}
/// <summary>
/// Gets or sets a value that indicates the amount that the
/// children of the <see cref="T:Avalonia.Controls.RowGroupHeader" /> are indented.
/// Gets or sets a value that indicates the amount that the
/// children of the <see cref="T:Avalonia.Controls.RowGroupHeader" /> are indented.
/// </summary>
public double SublevelIndent
{
@ -327,9 +327,9 @@ namespace Avalonia.Controls
{
double xClip = Math.Round(frozenLeftEdge - childLeftEdge);
var rg = new RectangleGeometry();
rg.Rect =
new Rect(xClip, 0,
Math.Max(0, child.Bounds.Width - xClip),
rg.Rect =
new Rect(xClip, 0,
Math.Max(0, child.Bounds.Width - xClip),
child.Bounds.Height);
child.Clip = rg;
}
@ -348,8 +348,6 @@ namespace Avalonia.Controls
}
}
//TODO Styles
//internal void EnsureHeaderStyleAndVisibility(Style previousStyle)
internal void EnsureHeaderVisibility()
{
if (_headerElement != null && OwningGrid != null)

72
src/Avalonia.Controls.DataGrid/DataGridRows.cs

@ -14,6 +14,9 @@ using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using Avalonia.Data;
using Avalonia.Styling;
using JetBrains.Annotations;
namespace Avalonia.Controls
{
@ -117,7 +120,7 @@ namespace Avalonia.Controls
detailsCount += GetDetailsCountInclusive(DisplayData.LastScrollingSlot + 1, SlotCount - 1);
}
//
//
double totalDetailsHeight = detailsCount * RowDetailsHeightEstimate;
return totalRowsHeight + totalDetailsHeight;
@ -163,7 +166,7 @@ namespace Avalonia.Controls
}
/// <summary>
/// Clears the entire selection except the indicated row. Displayed rows are deselected explicitly to
/// Clears the entire selection except the indicated row. Displayed rows are deselected explicitly to
/// visualize potential transition effects. The row indicated is selected if it is not already.
/// </summary>
internal void ClearRowSelection(int slotException, bool setAnchorSlot)
@ -270,10 +273,10 @@ namespace Avalonia.Controls
bool isRow = rowIndex != -1;
if (isCollapsed)
{
InsertElement(slot,
element: null,
InsertElement(slot,
element: null,
updateVerticalScrollBarOnly: true,
isCollapsed: true,
isCollapsed: true,
isRow: isRow);
}
else if (SlotIsDisplayed(slot))
@ -285,18 +288,18 @@ namespace Avalonia.Controls
}
else
{
InsertElement(slot, GenerateRowGroupHeader(slot, groupInfo),
InsertElement(slot, GenerateRowGroupHeader(slot, groupInfo),
updateVerticalScrollBarOnly: false,
isCollapsed: false,
isCollapsed: false,
isRow: isRow);
}
}
else
{
InsertElement(slot,
InsertElement(slot,
element: null,
updateVerticalScrollBarOnly: _vScrollBar == null || _vScrollBar.IsVisible,
isCollapsed: false,
isCollapsed: false,
isRow: isRow);
}
}
@ -417,7 +420,7 @@ namespace Avalonia.Controls
if (scrolledHorizontally && DisplayData.FirstScrollingSlot <= slot && DisplayData.LastScrollingSlot >= slot)
{
// If the slot is displayed and we scrolled horizontally, column virtualization could cause the rows to grow.
// As a result we need to force measure on the rows we're displaying and recalculate our First and Last slots
// As a result we need to force measure on the rows we're displaying and recalculate our First and Last slots
// so they're accurate
foreach (DataGridRow row in DisplayData.GetScrollingRows())
{
@ -455,7 +458,7 @@ namespace Avalonia.Controls
deltaY -= GetSlotElementsHeight(slot, firstFullSlot);
if (DisplayData.FirstScrollingSlot - slot > 1)
{
//
//
ResetDisplayedRows();
}
@ -519,7 +522,7 @@ namespace Avalonia.Controls
_verticalOffset = NegVerticalOffset;
}
//
//
Debug.Assert(MathUtilities.LessThanOrClose(NegVerticalOffset, _verticalOffset));
SetVerticalOffset(_verticalOffset);
@ -1025,6 +1028,10 @@ namespace Avalonia.Controls
dataGridRow.Slot = slot;
dataGridRow.OwningGrid = this;
dataGridRow.DataContext = dataContext;
if (RowTheme is {} rowTheme)
{
dataGridRow.SetValue(ThemeProperty, rowTheme, BindingPriority.TemplatedParent);
}
CompleteCellsCollection(dataGridRow);
OnLoadingRow(new DataGridRowEventArgs(dataGridRow));
@ -1104,7 +1111,7 @@ namespace Avalonia.Controls
/// <summary>
/// Checks if the row for the provided dataContext has been generated and is present
/// in either the loaded rows, pre-fetched rows, or editing row.
/// in either the loaded rows, pre-fetched rows, or editing row.
/// The displayed rows are *not* searched. Returns null if the row does not belong to those 3 categories.
/// </summary>
private DataGridRow GetGeneratedRow(object dataContext)
@ -1152,8 +1159,8 @@ namespace Avalonia.Controls
}
else
{
// If we're grouping, the GroupLevel needs to be fixed later by methods calling this
// which end up inserting rows. We don't do it here because elements could be inserted
// If we're grouping, the GroupLevel needs to be fixed later by methods calling this
// which end up inserting rows. We don't do it here because elements could be inserted
// from top to bottom or bottom to up so it's better to do in one pass
slotElement = GenerateRow(RowIndexFromSlot(slot), slot);
}
@ -1161,7 +1168,6 @@ namespace Avalonia.Controls
return slotElement;
}
//TODO Styles
private void InsertDisplayedElement(int slot, Control element, bool wasNewlyAdded, bool updateSlotInformation)
{
// We can only support creating new rows that are adjacent to the currently visible rows
@ -1479,7 +1485,6 @@ namespace Avalonia.Controls
}
}
//TODO Styles
// Makes sure the row shows the proper visuals for selection, currency, details, etc.
private void LoadRowVisualsForDisplay(DataGridRow row)
{
@ -1694,7 +1699,7 @@ namespace Avalonia.Controls
{
// Figure out what row we've scrolled down to and update the value for NegVerticalOffset
NegVerticalOffset = 0;
//
//
if (height > 2 * CellsHeight &&
(RowDetailsVisibilityMode != DataGridRowDetailsVisibilityMode.VisibleWhenSelected || RowDetailsTemplate == null))
{
@ -1755,7 +1760,7 @@ namespace Avalonia.Controls
// Figure out what row we've scrolled up to and update the value for NegVerticalOffset
deltaY = -NegVerticalOffset;
NegVerticalOffset = 0;
//
//
if (height < -2 * CellsHeight &&
(RowDetailsVisibilityMode != DataGridRowDetailsVisibilityMode.VisibleWhenSelected || RowDetailsTemplate == null))
@ -1813,7 +1818,7 @@ namespace Avalonia.Controls
if (MathUtilities.GreaterThanOrClose(0, newVerticalOffset) && newFirstScrollingSlot != 0)
{
// We've scrolled to the top of the ScrollBar, automatically place the user at the very top
// of the DataGrid. If this produces very odd behavior, evaluate the RowHeight estimate.
// of the DataGrid. If this produces very odd behavior, evaluate the RowHeight estimate.
// strategy. For most data, this should be unnoticeable.
ResetDisplayedRows();
NegVerticalOffset = 0;
@ -1994,7 +1999,6 @@ namespace Avalonia.Controls
VisibleSlotCount = 0;
}
//TODO Styles
private void UnloadRow(DataGridRow dataGridRow)
{
Debug.Assert(dataGridRow != null);
@ -2010,16 +2014,13 @@ namespace Avalonia.Controls
OnUnloadingRow(new DataGridRowEventArgs(dataGridRow));
bool recycleRow = CurrentSlot != dataGridRow.Index;
// Don't recycle if the row has a custom Style set
//recycleRow &= (dataGridRow.Style == null || dataGridRow.Style == RowStyle);
if (recycleRow)
{
DisplayData.AddRecyclableRow(dataGridRow);
}
else
{
//
//
_rowsPresenter.Children.Remove(dataGridRow);
dataGridRow.DetachFromDataGrid(false);
}
@ -2240,10 +2241,10 @@ namespace Avalonia.Controls
group.Items.CollectionChanged += CollectionViewGroup_CollectionChanged;
}
var newGroupInfo = new DataGridRowGroupInfo(group, true, parentGroupInfo.Level + 1, insertSlot, insertSlot);
InsertElementAt(insertSlot,
rowIndex: -1,
item: null,
groupInfo: newGroupInfo,
InsertElementAt(insertSlot,
rowIndex: -1,
item: null,
groupInfo: newGroupInfo,
isCollapsed: isCollapsed);
RowGroupHeadersTable.AddValue(insertSlot, newGroupInfo);
}
@ -2256,9 +2257,9 @@ namespace Avalonia.Controls
{
AutoGenerateColumnsPrivate();
}
InsertElementAt(insertSlot, rowIndex,
InsertElementAt(insertSlot, rowIndex,
item: e.NewItems[0],
groupInfo: null,
groupInfo: null,
isCollapsed: isCollapsed);
}
@ -2448,13 +2449,12 @@ namespace Avalonia.Controls
VisibleSlotCount = SlotCount;
}
//TODO Styles
private void RefreshRowGroupHeaders()
{
if (DataConnection.CollectionView != null
&& DataConnection.CollectionView.CanGroup
&& DataConnection.CollectionView.Groups != null
&& DataConnection.CollectionView.IsGrouping
&& DataConnection.CollectionView.IsGrouping
&& DataConnection.CollectionView.GroupingDepth > 0)
{
// Initialize our array for the height of the RowGroupHeaders by Level.
@ -2476,7 +2476,7 @@ namespace Avalonia.Controls
double indent;
for (int i = 0; i < groupLevelCount; i++)
{
indent = DATAGRID_defaultRowGroupSublevelIndent;
indent = DATAGRID_defaultRowGroupSublevelIndent;
RowGroupSublevelIndents[i] = indent;
if (i > 0)
{
@ -2742,6 +2742,10 @@ namespace Avalonia.Controls
groupHeader.RowGroupInfo = rowGroupInfo;
groupHeader.DataContext = rowGroupInfo.CollectionViewGroup;
groupHeader.Level = rowGroupInfo.Level;
if (RowGroupTheme is {} rowGroupTheme)
{
groupHeader.SetValue(ThemeProperty, rowGroupTheme, BindingPriority.TemplatedParent);
}
// Set the RowGroupHeader's PropertyName. Unfortunately, CollectionViewGroup doesn't have this
// so we have to set it manually

7
src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml

@ -232,7 +232,7 @@
<Setter Property="Data" Value="{StaticResource DataGridSortIconDescendingPath}" />
</Style>
</ControlTheme>
<ControlTheme x:Key="DataGridTopLeftColumnHeader" TargetType="DataGridColumnHeader" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
<Setter Property="Template">
<ControlTemplate>
@ -337,10 +337,6 @@
</ControlTemplate>
</Setter>
<Style Selector="^:nth-child(even)">
<Setter Property="Background" Value="{Binding $parent[DataGrid].AlternatingRowBackground}" />
</Style>
<Style Selector="^:invalid">
<Style Selector="^ /template/ Rectangle#InvalidVisualElement">
<Setter Property="Opacity" Value="0.4" />
@ -484,7 +480,6 @@
<ControlTheme x:Key="{x:Type DataGrid}" TargetType="DataGrid">
<Setter Property="RowBackground" Value="Transparent" />
<Setter Property="AlternatingRowBackground" Value="Transparent" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="VerticalScrollBarVisibility" Value="Auto" />

5
src/Avalonia.Controls.DataGrid/Themes/Simple.xaml

@ -200,10 +200,6 @@
</ControlTemplate>
</Setter>
<Style Selector="^:nth-child(even)">
<Setter Property="Background" Value="{Binding $parent[DataGrid].AlternatingRowBackground}" />
</Style>
<Style Selector="^ /template/ Rectangle#BackgroundRectangle">
<Setter Property="IsVisible" Value="False" />
<Setter Property="Fill" Value="{DynamicResource HighlightBrush}" />
@ -300,7 +296,6 @@
<ControlTheme x:Key="{x:Type DataGrid}"
TargetType="DataGrid">
<Setter Property="RowBackground" Value="{DynamicResource ThemeAccentBrush4}" />
<Setter Property="AlternatingRowBackground" Value="#00FFFFFF" />
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}" />
<Setter Property="HeadersVisibility" Value="Column" />
<Setter Property="HorizontalScrollBarVisibility" Value="Auto" />

Loading…
Cancel
Save