C
C#2y ago
barcode

❔ avalonia datagrid dynamic columns

I'm trying to create a mongodb client with Avalonia UI, I want to dynamically create columns in a datagrid that I'll fill with data. I ran into an issue where I can't get the Binding paremeter to read key value pairs properly, I tried Lists of Dictionaries, objects, BsonDocument however I always get something like this outputted:
7 Replies
JakenVeina
JakenVeina2y ago
so, I don't know how different Avalonia's DataGrid is from WPF's but this is a right CHORE in WPF not something you can do with just bindings in WPF, my approach was roughly the following...
public class MyDatasetViewModel
{
public IReadOnlyList<MyDatasetColumnViewModel> Columns { get; }
public IReadOnlyList<IReadOnlyList<MyDatasetValueViewModel>> Rows { get; }
}
public class MyDatasetViewModel
{
public IReadOnlyList<MyDatasetColumnViewModel> Columns { get; }
public IReadOnlyList<IReadOnlyList<MyDatasetValueViewModel>> Rows { get; }
}
Rows gets bound to ItemsSource and Columns gets bound to an attached property that manually builds the Columns array, with a DataGridTemplateColumn for each column in the bound array with the really tricky part being the building of that template in C# code, instead of XAML
Klarth
Klarth2y ago
Probably as hard or harder in Avalonia. I'd ask in the Avalonia Telegram if there are any good ideas for it. XAML doesn't really enjoy types that are only known at runtime, nor does it enjoy non-flat collections like dictionaries. You're going to have to do most of the work in code.
JakenVeina
JakenVeina2y ago
what do you mean by "XAML doesn't really enjoy types that are only known at runtime"? meaning anonymous types?
Klarth
Klarth2y ago
Anonymous types still are known at compile-time, no? I'm talking about most instances of when your app doesn't know the data schema of what the user is going to provide until runtime. Which fits any app that is loading arbitrary DB tables, CSV, XML, etc.
JakenVeina
JakenVeina2y ago
yeah, and I just gave a workable solution for it above
barcode
barcodeOP2y ago
i will try
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server