DataGrid is always empty
See original GitHub issueDescribe the bug
<DataGrid />
never has any content - it just appears to stay as an empty component.
To Reproduce
- Create a DataGrid in XAML
- Either bind
Items
to a viewmodel, or add items via code-behind - The given items will not show at all
Expected behavior
The data bound to Items
is used to create a table of information.
Screenshots
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:
- Created 2 years ago
- Comments:13 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Did you add styles in your App.axaml ?
or
https://docs.avaloniaui.net/docs/controls/datagrid#add-required-styles-to-app-axaml
Ohhhhhh I didnt realise how dynamicdata worked. Thank you so much, and sorry if I wasted your time.