{"id":4821,"date":"2023-01-09T18:00:31","date_gmt":"2023-01-09T17:00:31","guid":{"rendered":"https:\/\/ekiwi.de\/index.php\/4821\/avaloniaui-8211-datagrid-is-not-displayed\/"},"modified":"2023-01-14T19:09:38","modified_gmt":"2023-01-14T18:09:38","slug":"avaloniaui-8211-datagrid-is-not-displayed","status":"publish","type":"post","link":"https:\/\/ekiwi.de\/en\/index.php\/4821\/avaloniaui-8211-datagrid-is-not-displayed\/","title":{"rendered":"AvaloniaUI \u2013 DataGrid is not displayed"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of content<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ekiwi.de\/en\/index.php\/4821\/avaloniaui-8211-datagrid-is-not-displayed\/#Add_package\" >Add package<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ekiwi.de\/en\/index.php\/4821\/avaloniaui-8211-datagrid-is-not-displayed\/#Add_styles\" >Add styles<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ekiwi.de\/en\/index.php\/4821\/avaloniaui-8211-datagrid-is-not-displayed\/#Column_definition\" >Column definition<\/a><\/li><\/ul><\/nav><\/div>\n<p>DataGrid with AvaloniaUI does not work.<\/p>\n<p><!--more--><\/p>\n<p>I had the problem that the DataGrid component did not show up in my application. I added the DataGrid to a grid, but nothing showed up after running the program. There was also no error when compiling.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"\/wp-content\/uploads\/2023\/01\/grid_1.png\" alt=\"\" width=\"576\" height=\"122\" class=\"alignnone size-full wp-image-4798\" srcset=\"\/wp-content\/uploads\/2023\/01\/grid_1.png 576w, \/wp-content\/uploads\/2023\/01\/grid_1-300x64.png 300w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><\/p>\n<p>How to fix this?<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Add_package\"><\/span>Add package<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The first thing to do is to add the DataGrid component&#8217;s NuGet package to the project. By default, the DataGrid is not available. It is available via a transitive dependency on the &#8222;Avalonia.Diagnostics&#8220; package. This makes it run in debug mode, but not in release mode.<\/p>\n<p>.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"\/wp-content\/uploads\/2023\/01\/grid_2.png\" alt=\"\" width=\"360\" height=\"228\" class=\"alignnone size-full wp-image-4800\" srcset=\"\/wp-content\/uploads\/2023\/01\/grid_2.png 360w, \/wp-content\/uploads\/2023\/01\/grid_2-300x190.png 300w\" sizes=\"auto, (max-width: 360px) 100vw, 360px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Add_styles\"><\/span>Add styles<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>After that, you need to add the right styles for the grid to the application. Examples can be found <a href=\"https:\/\/docs.avaloniaui.net\/docs\/controls\/datagrid\" rel=\"noopener\" target=\"_blank\">in the documentation<\/a>.<\/p>\n<p>In my case, I had to add the styles for the theme &#8222;Fluent&#8220;.<\/p>\n<pre>&lt;Application.Styles&gt;\r\n&lt;FluentTheme Mode=&quot;Light&quot;\/&gt;\r\n&lt;StyleInclude Source=&quot;avares:\/\/Avalonia.Controls.DataGrid\/Themes\/Fluent.xaml&quot;\/&gt;\r\n&lt;\/Application.Styles&gt; <\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Column_definition\"><\/span>Column definition<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Still nothing was displayed. I found that I needed to define the column definitions. Either by generating the columns automatically or by defining them manually.<\/p>\n<pre>\r\nAutoGenerateColumns=\"True\"\r\n<\/pre>\n<p>After that, the DataGrid was finally displayed.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"\/wp-content\/uploads\/2023\/01\/grid_3.png\" alt=\"\" width=\"799\" height=\"137\" class=\"alignnone size-full wp-image-4802\" srcset=\"\/wp-content\/uploads\/2023\/01\/grid_3.png 799w, \/wp-content\/uploads\/2023\/01\/grid_3-300x51.png 300w, \/wp-content\/uploads\/2023\/01\/grid_3-768x132.png 768w\" sizes=\"auto, (max-width: 799px) 100vw, 799px\" \/><\/p>","protected":false},"excerpt":{"rendered":"<p>DataGrid with AvaloniaUI does not work.<\/p>\n","protected":false},"author":2,"featured_media":4244,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[870],"tags":[],"class_list":["post-4821","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/posts\/4821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/comments?post=4821"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/posts\/4821\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/media\/4244"}],"wp:attachment":[{"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/media?parent=4821"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/categories?post=4821"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi.de\/en\/index.php\/wp-json\/wp\/v2\/tags?post=4821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}