-
-
Notifications
You must be signed in to change notification settings - Fork 171
Update DataGrid.cs #941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Update DataGrid.cs #941
Conversation
Bind Column With ! Add CellStyle -ClassStyle Add HeaderStyle -ClassStyle Repaing EmptyView to Height
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds style class support for DataGrid cells and headers, introduces a converter for column width binding, and modifies the row definition logic to better handle empty views. The changes aim to enhance the styling capabilities of the DataGrid control and improve the rendering of empty states.
Changes:
- Added
ApplyStyleClassToViewmethod to apply style classes to header and cell views - Modified column width binding to use a converter with two-way binding support
- Updated row definitions to allocate a star-sized row for empty views when only headers are present
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!string.IsNullOrEmpty(column.HeaderStyleClass)) | ||
| { | ||
| ApplyStyleClassToView(titleView, column.HeaderStyleClass, new List<string> { "DataGridHeaderColumn"}); | ||
|
|
||
| } |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property 'HeaderStyleClass' does not exist in the DataGridColumn class. This will cause a compilation error. You need to add this property to the DataGridColumn class before using it here.
| if (!string.IsNullOrEmpty(column.HeaderStyleClass)) | |
| { | |
| ApplyStyleClassToView(titleView, column.HeaderStyleClass, new List<string> { "DataGridHeaderColumn"}); | |
| } |
| private void ApplyStyleClassToView(View view, string styleClasses,List<string> extClasses) | ||
| { | ||
| if (view == null) return; | ||
| List<string> nc=new List<string>(); |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing in variable declaration. There are two spaces before 'nc=', and no spaces around the assignment operator. It should be 'List nc = new List();' with proper spacing, consistent with C# conventions seen elsewhere in the codebase.
| List<string> nc=new List<string>(); | |
| List<string> nc = new List<string>(); |
| BindingContext = item, | ||
| }; | ||
|
|
||
| ApplyStyleClassToView(cell, column.CellStyleClass, new List<string> { "DataGridCellColumn"}); |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property 'CellStyleClass' does not exist in the DataGridColumn class. This will cause a compilation error. You need to add this property to the DataGridColumn class before using it here.
| ApplyStyleClassToView(cell, column.CellStyleClass, new List<string> { "DataGridCellColumn"}); | |
| ApplyStyleClassToView(cell, null, new List<string> { "DataGridCellColumn" }); |
| // Создайте ресурс конвертера | ||
| var converter = new UniversalGridLengthConverter(); | ||
|
|
||
| var columnDefinition = new ColumnDefinition(); |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect indentation. This line has inconsistent indentation with extra leading spaces. The 'var columnDefinition' declaration should be aligned with the other statements inside the for loop.
| var columnDefinition = new ColumnDefinition(); | |
| var columnDefinition = new ColumnDefinition(); |
| new Binding("Width", source: Columns[i]) | ||
| { | ||
| Converter = converter, | ||
| Mode = BindingMode.TwoWay // если нужно двустороннее связывание |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comment in Russian '// если нужно двустороннее связывание' is inconsistent with the rest of the codebase, which uses English comments. It should be translated to English, such as '// if two-way binding is needed'. Additionally, the comment suggests uncertainty about whether two-way binding is needed, which should be clarified.
| using System.ComponentModel.DataAnnotations; | ||
| using System.Reflection; | ||
| using UraniumUI.Extensions; | ||
| using UraniumUI.Material.Converters; |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The namespace 'UraniumUI.Material.Converters' does not exist in the codebase. The UniversalGridLengthConverter class referenced in this import and used on line 318 has not been defined or added in this PR. This will cause a compilation error. You need to either create this converter class or use an existing GridLength converter.
| @@ -1,3 +1,4 @@ | |||
|
|
|||
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An unnecessary empty line has been added at the beginning of the file. This should be removed to maintain consistency with C# file conventions.
| } | ||
|
|
||
|
|
||
| private void ApplyStyleClassToView(View view, string styleClasses,List<string> extClasses) |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after the comma in the parameter list. The parameter should be 'List extClasses' with a space after the comma, consistent with C# formatting conventions.
| private void ApplyStyleClassToView(View view, string styleClasses,List<string> extClasses) | |
| private void ApplyStyleClassToView(View view, string styleClasses, List<string> extClasses) |
| // Создайте ресурс конвертера | ||
| var converter = new UniversalGridLengthConverter(); | ||
|
|
||
| var columnDefinition = new ColumnDefinition(); | ||
| // Set the binding | ||
|
|
||
| // Устанавливаем привязку с конвертером | ||
| columnDefinition.SetBinding( | ||
| ColumnDefinition.WidthProperty, | ||
| new Binding("Width", source: Columns[i]) | ||
| { | ||
| Converter = converter, | ||
| Mode = BindingMode.TwoWay // если нужно двустороннее связывание |
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments in Russian are inconsistent with the rest of the codebase, which uses English comments. The comment '// Создайте ресурс конвертера' should be translated to English, such as '// Create converter resource'.
| // Создайте ресурс конвертера | |
| var converter = new UniversalGridLengthConverter(); | |
| var columnDefinition = new ColumnDefinition(); | |
| // Set the binding | |
| // Устанавливаем привязку с конвертером | |
| columnDefinition.SetBinding( | |
| ColumnDefinition.WidthProperty, | |
| new Binding("Width", source: Columns[i]) | |
| { | |
| Converter = converter, | |
| Mode = BindingMode.TwoWay // если нужно двустороннее связывание | |
| // Create converter resource | |
| var converter = new UniversalGridLengthConverter(); | |
| var columnDefinition = new ColumnDefinition(); | |
| // Set the binding | |
| // Set the binding with the converter | |
| columnDefinition.SetBinding( | |
| ColumnDefinition.WidthProperty, | |
| new Binding("Width", source: Columns[i]) | |
| { | |
| Converter = converter, | |
| Mode = BindingMode.TwoWay // if two-way binding is needed |
| @@ -210,12 +216,26 @@ protected virtual void AddTableHeaders(int row = 0) | |||
| // TODO: Use an attribute to localize it. | |||
| titleView.BindingContext = column; | |||
| titleView.SetBinding(View.IsVisibleProperty, nameof(DataGridColumn.IsVisible)); | |||
Copilot
AI
Jan 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of the Width binding from titleView appears to be intentional as the width is now handled at the ColumnDefinition level (lines 324-330). However, this changes the behavior: previously, individual header views could have their own width, but now the width is controlled by the column definition. Ensure this is the intended behavior and that it doesn't break existing usage where individual header views may have had custom widths.
| titleView.SetBinding(View.IsVisibleProperty, nameof(DataGridColumn.IsVisible)); | |
| titleView.SetBinding(View.IsVisibleProperty, nameof(DataGridColumn.IsVisible)); | |
| titleView.SetBinding(View.WidthRequestProperty, nameof(DataGridColumn.Width)); |
Bind Column With !
Add CellStyle -ClassStyle
Add HeaderStyle -ClassStyle
Repaing EmptyView to Height