├── .editorconfig ├── .gitattributes ├── .gitignore ├── Avalonia.Controls.DataGrid.sln ├── Directory.Build.props ├── azure-pipelines.yml ├── build ├── Assets │ └── Icon.png ├── SharedVersion.props └── avalonia.snk ├── global.json ├── licence.md ├── readme.md ├── release.md └── src ├── Avalonia.Controls.DataGrid.UnitTests ├── Avalonia.Controls.DataGrid.UnitTests.csproj ├── Collections │ ├── ComparerTests.cs │ └── DataGridSortDescriptionTests.cs ├── DataGridRowTests.cs ├── LeakTests.cs ├── Properties │ └── AssemblyInfo.cs └── Utils │ └── ReflectionHelperTests.cs ├── Avalonia.Controls.DataGrid ├── Automation │ └── Peers │ │ ├── DataGridAutomationPeer.cs │ │ ├── DataGridCellAutomationPeer.cs │ │ ├── DataGridColumnHeaderAutomationPeer.cs │ │ ├── DataGridColumnHeadersPresenterAutomationPeer.cs │ │ ├── DataGridDetailsPresenterAutomationPeer.cs │ │ └── DataGridRowAutomationPeer.cs ├── Avalonia.Controls.DataGrid.csproj ├── Collections │ ├── DataGridCollectionView.cs │ ├── DataGridGroupDescription.cs │ ├── DataGridSortDescription.cs │ └── IDataGridCollectionView.cs ├── DataGrid.cs ├── DataGridBoundColumn.cs ├── DataGridCell.cs ├── DataGridCellCollection.cs ├── DataGridCellCoordinates.cs ├── DataGridCheckBoxColumn.cs ├── DataGridClipboard.cs ├── DataGridColumn.cs ├── DataGridColumnCollection.cs ├── DataGridColumnHeader.cs ├── DataGridColumns.cs ├── DataGridDataConnection.cs ├── DataGridDisplayData.cs ├── DataGridEnumerations.cs ├── DataGridError.cs ├── DataGridFillerColumn.cs ├── DataGridLength.cs ├── DataGridRow.cs ├── DataGridRowGroupHeader.cs ├── DataGridRowGroupInfo.cs ├── DataGridRowHeader.cs ├── DataGridRows.cs ├── DataGridSelectedItemsCollection.cs ├── DataGridTemplateColumn.cs ├── DataGridTextColumn.cs ├── DataGridValueConverter.cs ├── EventArgs.cs ├── Extensions.cs ├── IndexToValueTable.cs ├── Primitives │ ├── DataGridCellsPresenter.cs │ ├── DataGridColumnHeadersPresenter.cs │ ├── DataGridDetailsPresenter.cs │ ├── DataGridFrozenGrid.cs │ └── DataGridRowsPresenter.cs ├── Properties │ └── AssemblyInfo.cs ├── Range.cs ├── Themes │ ├── Fluent.xaml │ └── Simple.xaml └── Utils │ ├── CellEditBinding.cs │ ├── DataGridHelper.cs │ ├── KeyboardHelper.cs │ ├── ReflectionHelper.cs │ ├── TreeHelper.cs │ └── ValidationUtil.cs └── DataGridSample ├── App.axaml ├── App.axaml.cs ├── Converters ├── GDPLengthConverter.cs └── GDPValueConverter.cs ├── DataGridPage.axaml ├── DataGridPage.axaml.cs ├── DataGridSample.csproj ├── MainWindow.axaml ├── MainWindow.axaml.cs ├── Models ├── Countries.cs ├── Country.cs └── Person.cs ├── Program.cs └── app.manifest /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Default settings: 7 | # A newline ending every file 8 | # Use 4 spaces as indentation 9 | [*] 10 | insert_final_newline = true 11 | indent_style = space 12 | indent_size = 4 13 | 14 | # C# files 15 | [*.cs] 16 | # New line preferences 17 | csharp_new_line_before_open_brace = all 18 | csharp_new_line_before_else = true 19 | csharp_new_line_before_catch = true 20 | csharp_new_line_before_finally = true 21 | csharp_new_line_before_members_in_object_initializers = true 22 | csharp_new_line_before_members_in_anonymous_types = true 23 | csharp_new_line_between_query_expression_clauses = true 24 | # trim_trailing_whitespace = true 25 | 26 | # Indentation preferences 27 | csharp_indent_block_contents = true 28 | csharp_indent_braces = false 29 | csharp_indent_case_contents = true 30 | csharp_indent_switch_labels = true 31 | csharp_indent_labels = one_less_than_current 32 | 33 | # avoid this. unless absolutely necessary 34 | dotnet_style_qualification_for_field = false:suggestion 35 | dotnet_style_qualification_for_property = false:suggestion 36 | dotnet_style_qualification_for_method = false:suggestion 37 | dotnet_style_qualification_for_event = false:suggestion 38 | 39 | # prefer var 40 | csharp_style_var_for_built_in_types = true 41 | csharp_style_var_when_type_is_apparent = true 42 | csharp_style_var_elsewhere = true:suggestion 43 | 44 | # use language keywords instead of BCL types 45 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion 46 | dotnet_style_predefined_type_for_member_access = true:suggestion 47 | 48 | # name all constant fields using PascalCase 49 | dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion 50 | dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields 51 | dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style 52 | 53 | dotnet_naming_symbols.constant_fields.applicable_kinds = field 54 | dotnet_naming_symbols.constant_fields.required_modifiers = const 55 | 56 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case 57 | 58 | # private static fields should have s_ prefix 59 | dotnet_naming_rule.private_static_fields_should_have_prefix.severity = suggestion 60 | dotnet_naming_rule.private_static_fields_should_have_prefix.symbols = private_static_fields 61 | dotnet_naming_rule.private_static_fields_should_have_prefix.style = private_static_prefix_style 62 | 63 | dotnet_naming_symbols.private_static_fields.applicable_kinds = field 64 | dotnet_naming_symbols.private_static_fields.required_modifiers = static 65 | dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private 66 | 67 | dotnet_naming_style.private_static_prefix_style.required_prefix = s_ 68 | dotnet_naming_style.private_static_prefix_style.capitalization = camel_case 69 | 70 | # internal and private fields should be _camelCase 71 | dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion 72 | dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields 73 | dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style 74 | 75 | dotnet_naming_symbols.private_internal_fields.applicable_kinds = field 76 | dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal 77 | 78 | dotnet_naming_style.camel_case_underscore_style.required_prefix = _ 79 | dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case 80 | 81 | # use accessibility modifiers 82 | dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion 83 | 84 | # Code style defaults 85 | dotnet_sort_system_directives_first = true 86 | csharp_preserve_single_line_blocks = true 87 | csharp_preserve_single_line_statements = false 88 | 89 | # Expression-level preferences 90 | dotnet_style_object_initializer = true:suggestion 91 | dotnet_style_collection_initializer = true:suggestion 92 | dotnet_style_explicit_tuple_names = true:suggestion 93 | dotnet_style_coalesce_expression = true:suggestion 94 | dotnet_style_null_propagation = true:suggestion 95 | 96 | # Expression-bodied members 97 | csharp_style_expression_bodied_methods = false:none 98 | csharp_style_expression_bodied_constructors = false:none 99 | csharp_style_expression_bodied_operators = false:none 100 | csharp_style_expression_bodied_properties = true:none 101 | csharp_style_expression_bodied_indexers = true:none 102 | csharp_style_expression_bodied_accessors = true:none 103 | 104 | # Pattern matching 105 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion 106 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion 107 | csharp_style_inlined_variable_declaration = true:suggestion 108 | 109 | # Null checking preferences 110 | csharp_style_throw_expression = true:suggestion 111 | csharp_style_conditional_delegate_call = true:suggestion 112 | 113 | # Space preferences 114 | csharp_space_after_cast = false 115 | csharp_space_after_colon_in_inheritance_clause = true 116 | csharp_space_after_comma = true 117 | csharp_space_after_dot = false 118 | csharp_space_after_keywords_in_control_flow_statements = true 119 | csharp_space_after_semicolon_in_for_statement = true 120 | csharp_space_around_binary_operators = before_and_after 121 | csharp_space_around_declaration_statements = false 122 | csharp_space_before_colon_in_inheritance_clause = true 123 | csharp_space_before_comma = false 124 | csharp_space_before_dot = false 125 | csharp_space_before_open_square_brackets = false 126 | csharp_space_before_semicolon_in_for_statement = false 127 | csharp_space_between_empty_square_brackets = false 128 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 129 | csharp_space_between_method_call_name_and_opening_parenthesis = false 130 | csharp_space_between_method_call_parameter_list_parentheses = false 131 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 132 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 133 | csharp_space_between_method_declaration_parameter_list_parentheses = false 134 | csharp_space_between_parentheses = false 135 | csharp_space_between_square_brackets = false 136 | space_within_single_line_array_initializer_braces = true 137 | 138 | #Net Analyzer 139 | dotnet_analyzer_diagnostic.category-Performance.severity = none #error - Uncomment when all violations are fixed. 140 | 141 | # CS0649: Field 'field' is never assigned to, and will always have its default value 'value' 142 | dotnet_diagnostic.CS0649.severity = error 143 | 144 | # CS1591: Missing XML comment for publicly visible type or member 145 | dotnet_diagnostic.CS1591.severity = suggestion 146 | 147 | # CS0162: Remove unreachable code 148 | dotnet_diagnostic.CS0162.severity = error 149 | # CA1018: Mark attributes with AttributeUsageAttribute 150 | dotnet_diagnostic.CA1018.severity = error 151 | # CA1304: Specify CultureInfo 152 | dotnet_diagnostic.CA1304.severity = warning 153 | # CA1802: Use literals where appropriate 154 | dotnet_diagnostic.CA1802.severity = warning 155 | # CA1813: Avoid unsealed attributes 156 | dotnet_diagnostic.CA1813.severity = error 157 | # CA1815: Override equals and operator equals on value types 158 | dotnet_diagnostic.CA1815.severity = warning 159 | # CA1820: Test for empty strings using string length 160 | dotnet_diagnostic.CA1820.severity = warning 161 | # CA1821: Remove empty finalizers 162 | dotnet_diagnostic.CA1821.severity = error 163 | # CA1822: Mark members as static 164 | dotnet_diagnostic.CA1822.severity = suggestion 165 | dotnet_code_quality.CA1822.api_surface = private, internal 166 | # CA1823: Avoid unused private fields 167 | dotnet_diagnostic.CA1823.severity = error 168 | # CA1825: Avoid zero-length array allocations 169 | dotnet_diagnostic.CA1825.severity = warning 170 | # CA1826: Use property instead of Linq Enumerable method 171 | dotnet_diagnostic.CA1826.severity = suggestion 172 | # CA1827: Do not use Count/LongCount when Any can be used 173 | dotnet_diagnostic.CA1827.severity = warning 174 | # CA1828: Do not use CountAsync/LongCountAsync when AnyAsync can be used 175 | dotnet_diagnostic.CA1828.severity = warning 176 | # CA1829: Use Length/Count property instead of Enumerable.Count method 177 | dotnet_diagnostic.CA1829.severity = warning 178 | #CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters 179 | dotnet_diagnostic.CA1847.severity = warning 180 | # CA1851: Possible multiple enumerations of IEnumerable collection 181 | dotnet_diagnostic.CA1851.severity = warning 182 | #CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method 183 | dotnet_diagnostic.CA1854.severity = warning 184 | #CA2211:Non-constant fields should not be visible 185 | dotnet_diagnostic.CA2211.severity = error 186 | 187 | # Wrapping preferences 188 | csharp_wrap_before_ternary_opsigns = false 189 | 190 | # Avalonia DevAnalyzer preferences 191 | dotnet_diagnostic.AVADEV2001.severity = error 192 | 193 | # Avalonia PublicAnalyzer preferences 194 | dotnet_diagnostic.AVP1000.severity = error 195 | dotnet_diagnostic.AVP1001.severity = error 196 | dotnet_diagnostic.AVP1002.severity = error 197 | dotnet_diagnostic.AVP1010.severity = error 198 | dotnet_diagnostic.AVP1011.severity = error 199 | dotnet_diagnostic.AVP1012.severity = warning 200 | dotnet_diagnostic.AVP1013.severity = error 201 | dotnet_diagnostic.AVP1020.severity = error 202 | dotnet_diagnostic.AVP1021.severity = error 203 | dotnet_diagnostic.AVP1022.severity = error 204 | dotnet_diagnostic.AVP1030.severity = error 205 | dotnet_diagnostic.AVP1031.severity = error 206 | dotnet_diagnostic.AVP1032.severity = error 207 | dotnet_diagnostic.AVP1040.severity = error 208 | dotnet_diagnostic.AVA2001.severity = error 209 | 210 | # Xaml files 211 | [*.{xaml,axaml}] 212 | indent_size = 2 213 | # DuplicateSetterError 214 | avalonia_xaml_diagnostic.AVLN2203.severity = error 215 | # StyleInMergedDictionaries 216 | avalonia_xaml_diagnostic.AVLN2204.severity = error 217 | # RequiredTemplatePartMissing 218 | avalonia_xaml_diagnostic.AVLN2205.severity = error 219 | # OptionalTemplatePartMissing 220 | avalonia_xaml_diagnostic.AVLN2206.severity = info 221 | # TemplatePartWrongType 222 | avalonia_xaml_diagnostic.AVLN2207.severity = error 223 | # ItemContainerInsideTemplate 224 | avalonia_xaml_diagnostic.AVLN2208.severity = error 225 | # Obsolete 226 | avalonia_xaml_diagnostic.AVLN5001.severity = error 227 | 228 | # Xml project files 229 | [*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] 230 | indent_size = 2 231 | 232 | # Xml build files 233 | [*.builds] 234 | indent_size = 2 235 | 236 | # Xml files 237 | [*.{xml,stylecop,resx,ruleset}] 238 | indent_size = 2 239 | 240 | # Xml config files 241 | [*.{props,targets,config,nuspec}] 242 | indent_size = 2 243 | 244 | [*.json] 245 | indent_size = 2 246 | 247 | # Shell scripts 248 | [*.sh] 249 | end_of_line = lf 250 | 251 | [*.{cmd,bat}] 252 | end_of_line = crlf 253 | 254 | # YAML config files 255 | [*.{yaml,yml}] 256 | indent_size = 2 257 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /Avalonia.Controls.DataGrid.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Controls.DataGrid", "src\Avalonia.Controls.DataGrid\Avalonia.Controls.DataGrid.csproj", "{AAFEDBAD-2E68-4CAD-8C21-132B166C43C6}" 4 | EndProject 5 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3ACF6285-9101-4A01-9C62-C2222FB8091C}" 6 | ProjectSection(SolutionItems) = preProject 7 | Directory.Build.props = Directory.Build.props 8 | build\SharedVersion.props = build\SharedVersion.props 9 | licence.md = licence.md 10 | readme.md = readme.md 11 | azure-pipelines.yml = azure-pipelines.yml 12 | EndProjectSection 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Avalonia.Controls.DataGrid.UnitTests", "src\Avalonia.Controls.DataGrid.UnitTests\Avalonia.Controls.DataGrid.UnitTests.csproj", "{91F13463-94A3-4635-96A2-EBB8A7D899DA}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataGridSample", "src\DataGridSample\DataGridSample.csproj", "{3F8265C6-4520-4E48-BFEC-F73E20F6EEDB}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Release|Any CPU = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {AAFEDBAD-2E68-4CAD-8C21-132B166C43C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {AAFEDBAD-2E68-4CAD-8C21-132B166C43C6}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {AAFEDBAD-2E68-4CAD-8C21-132B166C43C6}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {AAFEDBAD-2E68-4CAD-8C21-132B166C43C6}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {91F13463-94A3-4635-96A2-EBB8A7D899DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {91F13463-94A3-4635-96A2-EBB8A7D899DA}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {91F13463-94A3-4635-96A2-EBB8A7D899DA}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {91F13463-94A3-4635-96A2-EBB8A7D899DA}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {3F8265C6-4520-4E48-BFEC-F73E20F6EEDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {3F8265C6-4520-4E48-BFEC-F73E20F6EEDB}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {3F8265C6-4520-4E48-BFEC-F73E20F6EEDB}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {3F8265C6-4520-4E48-BFEC-F73E20F6EEDB}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | net8.0 5 | net6.0 6 | 12.0 7 | 11.3.0 8 | 0024000004800000940000000602000000240000525341310004000001000100c1bba1142285fe0419326fb25866ba62c47e6c2b5c1ab0c95b46413fad375471232cb81706932e1cef38781b9ebd39d5100401bacb651c6c5bbf59e571e81b3bc08d2a622004e08b1a6ece82a7e0b9857525c86d2b95fab4bc3dce148558d7f3ae61aa3a234086902aeface87d9dfdd32b9d2fe3c6dd4055b5ab4b104998bd87 9 | 10 | 11 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | pool: 2 | vmImage: ubuntu-latest 3 | 4 | variables: 5 | configuration: 'Release' 6 | lowerConfiguration: '${{ lower(variables.configuration) }}' 7 | versionSuffix: '' 8 | commonDotNetParameters: '--invalid-will-be-replaced' 9 | 10 | steps: 11 | 12 | - task: PowerShell@2 13 | displayName: 'Set non-release version suffix' 14 | condition: not(startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')) 15 | inputs: 16 | targetType: 'inline' 17 | script: | 18 | $versionSuffix = "-cibuild{0:D7}-alpha" -f $(Build.BuildId) 19 | Write-Output "Setting versionSuffix to '$versionSuffix'" 20 | Write-Output "##vso[task.setvariable variable=versionSuffix]$versionSuffix" 21 | 22 | - task: UseDotNet@2 23 | displayName: 'Install .NET SDK' 24 | inputs: 25 | packageType: sdk 26 | useGlobalJson: true 27 | 28 | - script: echo "##vso[task.setvariable variable=commonDotNetParameters]-c $(configuration) -p:CIBranchName='$(Build.SourceBranchName)' -p:CIVersionSuffix='$(versionSuffix)'" 29 | displayName: 'Set variables' 30 | 31 | - script: dotnet build $(commonDotNetParameters) --no-incremental 32 | displayName: 'Build solution' 33 | 34 | - script: dotnet test $(commonDotNetParameters) --logger trx --results-directory "artifacts/test/$(lowerConfiguration)" --no-build 35 | displayName: 'Run tests' 36 | 37 | - script: dotnet pack $(commonDotNetParameters) --no-build 38 | displayName: 'Create package' 39 | 40 | - task: PublishTestResults@2 41 | displayName: 'Publish test results' 42 | inputs: 43 | testResultsFormat: 'VSTest' 44 | testResultsFiles: 'artifacts/test/$(lowerConfiguration)/*.trx' 45 | condition: not(canceled()) 46 | 47 | - task: PublishBuildArtifacts@1 48 | displayName: 'Publish package' 49 | inputs: 50 | PathtoPublish: '$(Build.SourcesDirectory)/artifacts/package/$(lowerConfiguration)/' 51 | ArtifactName: 'drop' 52 | publishLocation: 'Container' 53 | -------------------------------------------------------------------------------- /build/Assets/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AvaloniaUI/Avalonia.Controls.DataGrid/a6d637c08f9b56b5c7c9f11674166f0ed3ec0a43/build/Assets/Icon.png -------------------------------------------------------------------------------- /build/SharedVersion.props: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | Avalonia 6 | 11.3.999$(CIVersionSuffix) 7 | Avalonia Team 8 | Copyright 2013-$([System.DateTime]::Now.ToString(`yyyy`)) © The AvaloniaUI Project 9 | https://avaloniaui.net/?utm_source=nuget&utm_medium=referral&utm_content=project_homepage_link 10 | https://github.com/AvaloniaUI/Avalonia.Controls.DataGrid 11 | $(NoWarn);CS1591 12 | MIT 13 | Icon.png 14 | Avalonia is a cross-platform UI framework for .NET providing a flexible styling system and supporting a wide range of Operating Systems such as Windows, Linux, macOS and with experimental support for Android, iOS and WebAssembly. 15 | avalonia;avaloniaui;mvvm;rx;reactive extensions;android;ios;mac;forms;wpf;net;netstandard;net461;uwp;xamarin 16 | https://github.com/AvaloniaUI/Avalonia.Controls.DataGrid/releases 17 | readme.md 18 | git 19 | $(MSBuildThisFileDirectory)/avalonia.snk 20 | true 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /build/avalonia.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AvaloniaUI/Avalonia.Controls.DataGrid/a6d637c08f9b56b5c7c9f11674166f0ed3ec0a43/build/avalonia.snk -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "sdk": { 3 | "version": "8.0.406", 4 | "rollForward": "latestFeature" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /licence.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) AvaloniaUI OÜ 4 | All Rights Reserved 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | [![NuGet](https://img.shields.io/nuget/v/Avalonia.Controls.DataGrid.svg)](https://www.nuget.org/packages/Avalonia.Controls.DataGrid/) 2 | 3 | # Avalonia DataGrid 4 | 5 | ## About 6 | 7 | The official `DataGrid` control for [Avalonia](https://github.com/AvaloniaUI/Avalonia). 8 | 9 | It displays repeating data in a customizable grid. 10 | See the [documentation](https://docs.avaloniaui.net/docs/reference/controls/datagrid/) for more information. 11 | 12 | ## Status 13 | 14 | The `DataGrid` control was initially ported from Silverlight, and was previously part of the [Avalonia main repository](https://github.com/AvaloniaUI/Avalonia). 15 | It now lives in its [own repository](https://github.com/AvaloniaUI/Avalonia.Controls.DataGrid): see [this discussion](https://github.com/AvaloniaUI/Avalonia/discussions/18388) for details. 16 | -------------------------------------------------------------------------------- /release.md: -------------------------------------------------------------------------------- 1 | # Release instructions 2 | 3 | ## Branch and Tag 4 | 5 | 1. Create a branch named `release/` (e.g. `release/11.2.6`) for a specific version. 6 | 2. Update the version in `SharedVersion.props`, e.g. `11.2.6` 7 | 3. Add a matching tag for this version, e.g. `git tag -a 11.2.6` 8 | 4. Push the release branch and the tag. 9 | 10 | ## CI Build 11 | 12 | 5. Wait for Azure Pipelines to finish the build. A matching build in the `nuget-feed-all` feed should be released soon after. 13 | 6. Using the build, run a due diligence test to make sure you're happy with the package. 14 | 7. On Azure Pipelines, on the build for your release, click on the badge for *NuGet (Release!)* then click on *Deploy*. 15 | 16 | ## GitHub Release 17 | 18 | 8. Make a new release on GitHub releases. 19 | 9. Select the tag matching the version, then click on *Generate release notes*. 20 | 10. Review the release information, then click on *Publish release*. 21 | -------------------------------------------------------------------------------- /src/Avalonia.Controls.DataGrid.UnitTests/Avalonia.Controls.DataGrid.UnitTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(AvsCurrentTargetFramework) 5 | Library 6 | true 7 | false 8 | enable 9 | Avalonia.Controls.DataGridTests 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | all 25 | runtime; build; native; contentfiles; analyzers; buildtransitive 26 | 27 | 28 | all 29 | runtime; build; native; contentfiles; analyzers; buildtransitive 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/Avalonia.Controls.DataGrid.UnitTests/Collections/ComparerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Diagnostics.CodeAnalysis; 5 | using System.Linq; 6 | using Avalonia.Collections; 7 | using Avalonia.Logging; 8 | using Xunit; 9 | 10 | namespace Avalonia.Controls.DataGridTests.Collections; 11 | 12 | public class NoStringTypeComparerTests 13 | { 14 | public static IEnumerable GetComparerForNotStringTypeParameters() 15 | { 16 | yield return 17 | [ 18 | nameof(Item.IntProp1), 19 | (object item, object value) => 20 | { 21 | (item as Item)!.IntProp1 = (int)value; 22 | }, 23 | (object item) => (object)(item as Item)!.IntProp1, 24 | new object?[] { 2, 3, 1 }, 25 | new object?[] { 1, 2, 3 } 26 | ]; 27 | yield return 28 | [ 29 | nameof(Item.IntProp2), 30 | (object item, object value) => 31 | { 32 | (item as Item)!.IntProp2 = (int?)value; 33 | }, 34 | (object item) => (object?)(item as Item)!.IntProp2, 35 | new object?[] { 2, 3, null, 1 }, 36 | new object?[] { null, 1, 2, 3 } 37 | ]; 38 | yield return 39 | [ 40 | nameof(Item.DoubleProp1), 41 | (object item, object value) => 42 | { 43 | (item as Item)!.DoubleProp1 = (double)value; 44 | }, 45 | (object item) => (object)(item as Item)!.DoubleProp1, 46 | new object?[] { 2.1, 3.1, 1.1 }, 47 | new object?[] { 1.1, 2.1, 3.1 } 48 | ]; 49 | yield return 50 | [ 51 | nameof(Item.DoubleProp2), 52 | (object item, object value) => 53 | { 54 | (item as Item)!.DoubleProp2 = (double?)value; 55 | }, 56 | (object item) => (object?)(item as Item)!.DoubleProp2, 57 | new object?[] { 2.1, 3.1, null, 1.1 }, 58 | new object?[] { null, 1.1, 2.1, 3.1 } 59 | ]; 60 | yield return 61 | [ 62 | nameof(Item.DecimalProp1), 63 | (object item, object value) => 64 | { 65 | (item as Item)!.DecimalProp1 = (decimal)value; 66 | }, 67 | (object item) => (object)(item as Item)!.DecimalProp1, 68 | new object?[] { 2.1M, 3.1M, 1.1M }, 69 | new object?[] { 1.1M, 2.1M, 3.1M } 70 | ]; 71 | yield return 72 | [ 73 | nameof(Item.DecimalProp2), 74 | (object item, object value) => 75 | { 76 | (item as Item)!.DecimalProp2 = (decimal?)value; 77 | }, 78 | (object item) => (object?)(item as Item)!.DecimalProp2, 79 | new object?[] { 2.1M, 3.1M, null, 1.1M }, 80 | new object?[] { null, 1.1M, 2.1M, 3.1M } 81 | ]; 82 | yield return 83 | [ 84 | nameof(Item.EnumProp1), 85 | (object item, object value) => 86 | { 87 | (item as Item)!.EnumProp1 = (LogEventLevel)value; 88 | }, 89 | (object item) => (object)(item as Item)!.EnumProp1, 90 | new object?[] { LogEventLevel.Information, LogEventLevel.Debug, LogEventLevel.Error }, 91 | new object?[] { LogEventLevel.Debug, LogEventLevel.Information, LogEventLevel.Error } 92 | ]; 93 | yield return 94 | [ 95 | nameof(Item.EnumProp2), 96 | (object item, object value) => 97 | { 98 | (item as Item)!.EnumProp2 = (LogEventLevel?)value; 99 | }, 100 | (object item) => (object?)(item as Item)!.EnumProp2, 101 | new object?[] 102 | { 103 | LogEventLevel.Information, 104 | LogEventLevel.Debug, 105 | null, 106 | LogEventLevel.Error 107 | }, 108 | new object?[] 109 | { 110 | null, 111 | LogEventLevel.Debug, 112 | LogEventLevel.Information, 113 | LogEventLevel.Error 114 | } 115 | ]; 116 | yield return 117 | [ 118 | nameof(Item.CustomProp2), 119 | (object item, object value) => 120 | { 121 | (item as Item)!.CustomProp2 = (CustomType?)value; 122 | }, 123 | (object item) => (object?)(item as Item)!.CustomProp2, 124 | new object?[] 125 | { 126 | new CustomType() { Prop = 2 }, 127 | new CustomType() { Prop = 3 }, 128 | null, 129 | new CustomType() { Prop = 1 } 130 | }, 131 | new object?[] 132 | { 133 | null, 134 | new CustomType() { Prop = 1 }, 135 | new CustomType() { Prop = 2 }, 136 | new CustomType() { Prop = 3 } 137 | } 138 | ]; 139 | } 140 | 141 | [Theory] 142 | [MemberData(nameof(GetComparerForNotStringTypeParameters))] 143 | public void GetComparerForNotStringType_Correctly_WhenSorting( 144 | string pathName, 145 | Action setAction, 146 | Func getAction, 147 | object?[] orignal, 148 | object?[] ordered 149 | ) 150 | { 151 | List items = new(); 152 | for (int i = 0; i < orignal.Length; i++) 153 | { 154 | var item = new Item(); 155 | setAction(item, orignal[i]); 156 | items.Add(item); 157 | } 158 | 159 | //Ascending 160 | var sortDescription = DataGridSortDescription.FromPath( 161 | pathName, 162 | ListSortDirection.Ascending 163 | ); 164 | sortDescription.Initialize(typeof(Item)); 165 | var result = sortDescription.OrderBy(items).ToList(); 166 | 167 | for (int i = 0; i < ordered.Length; i++) 168 | { 169 | Assert.Equal(ordered[i], getAction(result[i])); 170 | } 171 | 172 | //Descending 173 | sortDescription = DataGridSortDescription.FromPath(pathName, ListSortDirection.Descending); 174 | sortDescription.Initialize(typeof(Item)); 175 | result = sortDescription.OrderBy(items).ToList(); 176 | 177 | ordered = ordered.Reverse().ToArray(); 178 | for (int i = 0; i < ordered.Length; i++) 179 | { 180 | Assert.Equal(ordered[i], getAction(result[i])); 181 | } 182 | } 183 | 184 | private class Item 185 | { 186 | public int IntProp1 { get; set; } 187 | public int? IntProp2 { get; set; } 188 | public double DoubleProp1 { get; set; } 189 | public double? DoubleProp2 { get; set; } 190 | 191 | public decimal DecimalProp1 { get; set; } 192 | public decimal? DecimalProp2 { get; set; } 193 | 194 | public LogEventLevel EnumProp1 { get; set; } 195 | public LogEventLevel? EnumProp2 { get; set; } 196 | public CustomType? CustomProp2 { get; set; } 197 | } 198 | 199 | [SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "Unit test")] 200 | public struct CustomType : IComparable 201 | { 202 | public int Prop { get; set; } 203 | 204 | public int CompareTo(object? obj) 205 | { 206 | if (obj is CustomType other) 207 | { 208 | return Prop.CompareTo(other.Prop); 209 | } 210 | else 211 | { 212 | return 1; 213 | } 214 | } 215 | 216 | public override bool Equals(object? obj) 217 | { 218 | if (obj is CustomType other) 219 | { 220 | return Prop == other.Prop; 221 | } 222 | return false; 223 | } 224 | 225 | public override int GetHashCode() 226 | => Prop; 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /src/Avalonia.Controls.DataGrid.UnitTests/Collections/DataGridSortDescriptionTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Linq; 4 | using Avalonia.Collections; 5 | using Xunit; 6 | 7 | namespace Avalonia.Controls.DataGridTests.Collections 8 | { 9 | 10 | public class DataGridSortDescriptionTests 11 | { 12 | [Fact] 13 | public void OrderBy_Orders_Correctly_When_Ascending() 14 | { 15 | var items = new[] 16 | { 17 | new Item("b", "b"), 18 | new Item("a", "a"), 19 | new Item("c", "c"), 20 | }; 21 | var expectedResult = items.OrderBy(i => i.Prop1).ToList(); 22 | var sortDescription = DataGridSortDescription.FromPath(nameof(Item.Prop1), ListSortDirection.Ascending); 23 | 24 | sortDescription.Initialize(typeof(Item)); 25 | var result = sortDescription.OrderBy(items).ToList(); 26 | 27 | Assert.Equal(expectedResult, result); 28 | } 29 | 30 | [Fact] 31 | public void OrderBy_Orders_Correctly_When_Descending() 32 | { 33 | var items = new[] 34 | { 35 | new Item("b", "b"), 36 | new Item("a", "a"), 37 | new Item("c", "c"), 38 | }; 39 | var expectedResult = items.OrderByDescending(i => i.Prop1).ToList(); 40 | var sortDescription = DataGridSortDescription.FromPath(nameof(Item.Prop1), ListSortDirection.Descending); 41 | 42 | sortDescription.Initialize(typeof(Item)); 43 | var result = sortDescription.OrderBy(items).ToList(); 44 | 45 | Assert.Equal(expectedResult, result); 46 | } 47 | 48 | [Fact] 49 | public void ThenBy_Orders_Correctly_When_Ascending() 50 | { 51 | // Casting nonsense below because IOrderedEnumerable isn't covariant in full framework and we need an 52 | // object of type IOrderedEnumerable for DataGridSortDescription.ThenBy 53 | var items = new[] 54 | { 55 | (object)new Item("a", "b"), 56 | new Item("a", "a"), 57 | new Item("a", "c"), 58 | }.OrderBy(i => ((Item)i).Prop1); 59 | var expectedResult = new[] 60 | { 61 | new Item("a", "a"), 62 | new Item("a", "b"), 63 | new Item("a", "c"), 64 | }; 65 | var sortDescription = DataGridSortDescription.FromPath(nameof(Item.Prop2), ListSortDirection.Ascending); 66 | 67 | sortDescription.Initialize(typeof(Item)); 68 | var result = sortDescription.ThenBy(items).ToList(); 69 | 70 | Assert.Equal(expectedResult, result); 71 | } 72 | 73 | [Fact] 74 | public void ThenBy_Orders_Correctly_When_Descending() 75 | { 76 | // Casting nonsense below because IOrderedEnumerable isn't covariant in full framework and we need an 77 | // object of type IOrderedEnumerable for DataGridSortDescription.ThenBy 78 | var items = new[] 79 | { 80 | (object)new Item("a", "b"), 81 | new Item("a", "a"), 82 | new Item("a", "c"), 83 | }.OrderBy(i => ((Item)i).Prop1); 84 | var expectedResult = new[] 85 | { 86 | new Item("a", "c"), 87 | new Item("a", "b"), 88 | new Item("a", "a"), 89 | }; 90 | var sortDescription = DataGridSortDescription.FromPath(nameof(Item.Prop2), ListSortDirection.Descending); 91 | 92 | sortDescription.Initialize(typeof(Item)); 93 | var result = sortDescription.ThenBy(items).ToList(); 94 | 95 | Assert.Equal(expectedResult, result); 96 | } 97 | 98 | private class Item : IEquatable 99 | { 100 | public Item(string? prop1, string? prop2) 101 | { 102 | Prop1 = prop1; 103 | Prop2 = prop2; 104 | } 105 | 106 | public string? Prop1 { get; } 107 | public string? Prop2 { get; } 108 | 109 | public bool Equals(Item? other) 110 | { 111 | if (ReferenceEquals(null, other)) return false; 112 | if (ReferenceEquals(this, other)) return true; 113 | return Prop1 == other.Prop1 && Prop2 == other.Prop2; 114 | } 115 | 116 | public override bool Equals(object? obj) 117 | { 118 | if (ReferenceEquals(null, obj)) return false; 119 | if (ReferenceEquals(this, obj)) return true; 120 | if (obj.GetType() != this.GetType()) return false; 121 | return Equals((Item) obj); 122 | } 123 | 124 | public override int GetHashCode() 125 | { 126 | unchecked 127 | { 128 | return ((Prop1 != null ? Prop1.GetHashCode() : 0) * 397) ^ (Prop2 != null ? Prop2.GetHashCode() : 0); 129 | } 130 | } 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/Avalonia.Controls.DataGrid.UnitTests/DataGridRowTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Runtime.CompilerServices; 8 | using Avalonia.Controls.Shapes; 9 | using Avalonia.Data; 10 | using Avalonia.Headless.XUnit; 11 | using Avalonia.Markup.Xaml.Styling; 12 | using Avalonia.Markup.Xaml.Templates; 13 | using Avalonia.Styling; 14 | using Avalonia.VisualTree; 15 | using Xunit; 16 | 17 | namespace Avalonia.Controls.DataGridTests; 18 | 19 | public class DataGridRowTests 20 | { 21 | [AvaloniaFact] 22 | public void IsSelected_Binding_Works_For_Initial_Rows() 23 | { 24 | var items = Enumerable.Range(0, 100).Select(x => new Model($"Item {x}")).ToList(); 25 | items[2].IsSelected = true; 26 | 27 | var target = CreateTarget(items, [IsSelectedBinding()]); 28 | var rows = GetRows(target); 29 | 30 | Assert.Equal(0, GetFirstRealizedRowIndex(target)); 31 | Assert.Equal(4, GetLastRealizedRowIndex(target)); 32 | Assert.All(rows, x => Assert.Equal(x.Index == 2, x.IsSelected)); 33 | } 34 | 35 | [AvaloniaFact] 36 | public void IsSelected_Binding_Works_For_Rows_Scrolled_Into_View() 37 | { 38 | var items = Enumerable.Range(0, 100).Select(x => new Model($"Item {x}")).ToList(); 39 | items[10].IsSelected = true; 40 | 41 | var target = CreateTarget(items, [IsSelectedBinding()]); 42 | var rows = GetRows(target); 43 | 44 | Assert.Equal(0, GetFirstRealizedRowIndex(target)); 45 | Assert.Equal(4, GetLastRealizedRowIndex(target)); 46 | 47 | target.ScrollIntoView(items[10], target.Columns[0]); 48 | target.UpdateLayout(); 49 | 50 | Assert.Equal(6, GetFirstRealizedRowIndex(target)); 51 | Assert.Equal(10, GetLastRealizedRowIndex(target)); 52 | 53 | Assert.All(rows, x => Assert.Equal(x.Index == 10, x.IsSelected)); 54 | } 55 | 56 | [AvaloniaFact] 57 | public void Can_Toggle_IsSelected_Via_Binding() 58 | { 59 | var items = Enumerable.Range(0, 100).Select(x => new Model($"Item {x}")).ToList(); 60 | items[2].IsSelected = true; 61 | 62 | var target = CreateTarget(items, [IsSelectedBinding()]); 63 | var rows = GetRows(target); 64 | 65 | Assert.Equal(0, GetFirstRealizedRowIndex(target)); 66 | Assert.Equal(4, GetLastRealizedRowIndex(target)); 67 | Assert.All(rows, x => Assert.Equal(x.Index == 2, x.IsSelected)); 68 | 69 | items[2].IsSelected = false; 70 | 71 | Assert.All(rows, x => Assert.False(x.IsSelected)); 72 | } 73 | 74 | [AvaloniaFact] 75 | public void Can_Toggle_IsSelected_Via_DataGrid() 76 | { 77 | var items = Enumerable.Range(0, 100).Select(x => new Model($"Item {x}")).ToList(); 78 | items[2].IsSelected = true; 79 | 80 | var target = CreateTarget(items, [IsSelectedBinding()]); 81 | var rows = GetRows(target); 82 | 83 | Assert.Equal(0, GetFirstRealizedRowIndex(target)); 84 | Assert.Equal(4, GetLastRealizedRowIndex(target)); 85 | Assert.All(rows, x => Assert.Equal(x.Index == 2, x.IsSelected)); 86 | 87 | target.SelectedItems.Remove(items[2]); 88 | 89 | Assert.All(rows, x => Assert.False(x.IsSelected)); 90 | Assert.False(items[2].IsSelected); 91 | } 92 | 93 | [AvaloniaFact] 94 | public void DataGridRow_Bounds_Match_DataGrid_When_Header_Present() 95 | { 96 | var items = Enumerable.Range(0, 100).Select(x => new Model($"Item {x}")).ToList(); 97 | DataGrid target = CreateTarget(items, [WithHeader()]); 98 | 99 | // target.HeadersVisibility = DataGridHeadersVisibility.All; 100 | var rows = GetRows(target); 101 | 102 | Assert.All(rows, x => Assert.Equal(target.Bounds.Width, x.Bounds.Width)); 103 | } 104 | 105 | private static DataGrid CreateTarget( 106 | IList items, 107 | IEnumerable 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 66 | 67 | 68 | 69 | 70 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 104 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |