question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataGrid is always empty

See original GitHub issue

Describe the bug <DataGrid /> never has any content - it just appears to stay as an empty component.

To Reproduce

  1. Create a DataGrid in XAML
  2. Either bind Items to a viewmodel, or add items via code-behind
  3. The given items will not show at all

Expected behavior The data bound to Items is used to create a table of information.

Screenshots image

Desktop (please complete the following information):

  • OS: Arch Linux
  • Version 0.10.6

Additional context Have tested with and without MVVM, have tested with and without custom columns, have tested with both fields and properties for the member in objects given.

Basically what I wrote on top of the MVVM template:

Class:

public class Song
{
	public string Name;
	public string Artist;
	public string Album;

	public Song(string name, string artist, string album)
	{
		Name   = name;
		Artist = artist;
		Album  = album;
	}
}

In ViewModel:

public class MainWindowViewModel : ViewModelBase
{
	private SourceList<Song> _songs = new();

	public SourceList<Song> Songs
	{
		get => _songs;
		set => this.RaiseAndSetIfChanged(ref _songs, value);
	}
}

In constructor:

public MainWindow()
{
	DataContext = new MainWindowViewModel();
	
	InitializeComponent();
#if DEBUG
	this.AttachDevTools();
#endif

	((MainWindowViewModel) DataContext!).Songs.Add(new("Start Again", "ONE OK ROCK", "Ambitions"));

In XAML

<DataGrid Items="{Binding Songs.Items}" AutoGenerateColumns="False">

	<DataGrid.Columns>
		<DataGridTextColumn Header="Song" Binding="{Binding Name}" />
		<DataGridTextColumn Header="Artist" Binding="{Binding Artist}" />
		<DataGridTextColumn Header="Album" Binding="{Binding Album}" />
	</DataGrid.Columns>
		
</DataGrid>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
wieslawsoltescommented, Jul 11, 2021

Did you add styles in your App.axaml ?

<Application.Styles>
    <StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Default.xaml"/>
</Application.Styles>

or

<Application.Styles>
    <StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
</Application.Styles>

https://docs.avaloniaui.net/docs/controls/datagrid#add-required-styles-to-app-axaml

0reactions
yellowsinkcommented, Jul 20, 2021

Ohhhhhh I didnt realise how dynamicdata worked. Thank you so much, and sorry if I wasted your time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DataGrid empty row by default (and always)
I try to make DataGrid with empty row by default and if user delete all rows- datagrid shoud add e new empty row....
Read more >
An extra empty column is always shown in the datagrid for ...
It's just that the data grid usually has wide enough columns that there's no extra space.
Read more >
DataGrid - Always have empty/new row in batch edit mode
Hi everyone,. we want the datagrid to always have a completely empty row in batch edit mode. That means that as soon as...
Read more >
Empty value always comes in While using it as a Data Grid ...
Yes its true 'Empty' value show up in DataGrid filter for Enum Values. You can put Custom JavaScript code using Html/JS snippet in...
Read more >
DataGrid - The editing.changes array is empty after ...
I have a datagrid that uses row editing. One of the cells in every row is a user comment, and I want to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found