diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml b/samples/ControlCatalog/Pages/DataGridPage.xaml index 88252091c4b..a968b506665 100644 --- a/samples/ControlCatalog/Pages/DataGridPage.xaml +++ b/samples/ControlCatalog/Pages/DataGridPage.xaml @@ -45,6 +45,11 @@ + + + diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs b/samples/ControlCatalog/Pages/DataGridPage.xaml.cs index 617b0db5ed5..149b36fc3f7 100644 --- a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DataGridPage.xaml.cs @@ -24,7 +24,6 @@ public DataGridPage() collectionView1.SortDescriptions.Add(dataGridSortDescription); var dg1 = this.Get("dataGrid1"); dg1.IsReadOnly = true; - dg1.LoadingRow += Dg1_LoadingRow; dg1.Sorting += (s, a) => { var binding = (a.Column as DataGridBoundColumn)?.Binding as Binding; @@ -64,11 +63,6 @@ public DataGridPage() } public IEnumerable DataGrid3Source { get; } - - private void Dg1_LoadingRow(object? sender, DataGridRowEventArgs e) - { - e.Row.Header = e.Row.GetIndex() + 1; - } private void InitializeComponent() { diff --git a/src/Avalonia.Controls.DataGrid/DataGridRow.cs b/src/Avalonia.Controls.DataGrid/DataGridRow.cs index 5a312e8b7c3..146461f2a79 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridRow.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridRow.cs @@ -220,13 +220,18 @@ internal DataGrid OwningGrid set; } + private int _index; + + public static readonly DirectProperty IndexProperty = AvaloniaProperty.RegisterDirect( + nameof(Index), o => o.Index, (o, v) => o.Index = v); + /// /// Index of the row /// - internal int Index + public int Index { - get; - set; + get => _index; + internal set => SetAndRaise(IndexProperty, ref _index, value); } internal double ActualBottomGridLineHeight @@ -435,6 +440,7 @@ internal double TargetHeight /// /// The index of the current row. /// + [Obsolete("This API is going to be removed in a future version. Use the Index property instead.")] public int GetIndex() { return Index;