Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi, I would like to know if it is possible to use a dynamic collection as an itemsSource because the header and data don't have a defined structure(it's determined in runtime).

You must be logged in to vote

My problem was that the option Auto-generating Columns doesn't work with dictionaries or ExpandoObject, so I fixed it by creating the columns manually. Thanks for your help.

Replies: 1 comment · 5 replies

Comment options

Hi @Rafucho25, It might be possible to support a dynamic collection as an ItemsSource, but it depends on how the data is structured at runtime. If you can share a sample of the collection you're using, I can take a look and see if it works as-is or if any changes are needed. If adjustments are required, I’ll consider them for a future release.

You must be logged in to vote
5 replies
@w-ahmad
Comment options

@Rafucho25 Sorry for the late reply. If I understand correctly, you need to add your data to a dictionary and create the bindings accordingly. This will provide an accurate display, but the built-in sorting and filter might not work properly, which you can override write your own logic. I will try to fix this issue in the upcoming release. Thanks

public ObservableCollection<IDictionary<string, object?>> Items { get; set; } = [];

Items.Add(new Dictionary<string, object?>
{
    [nameof(ExampleModel.Id)] = item.Id,
    [nameof(ExampleModel.FirstName)] = item.FirstName,
    [nameof(ExampleModel.LastName)] = item.LastName,
    [nameof(ExampleModel.Email)] = item.Email,
    [nameof(ExampleModel.Gender)] = item.Gender,
    [nameof(ExampleModel.Dob)] = item.Dob,
    [nameof(ExampleModel.IsActive)] = item.IsActive,
    [nameof(ExampleModel.ActiveAt)] = item.ActiveAt,
    [nameof(ExampleModel.Department)] = item.Department,
    [nameof(ExampleModel.Designation)] = item.Designation,
    [nameof(ExampleModel.Address)] = item.Address,
    [nameof(ExampleModel.Avatar)] = item.Avatar
});
@Georgios1999
Comment options

[nameof(ExampleModel.Gender)] = item.Gender

Is it necessary that we use the example model dictionary? Any way to create our own one like Gender (which shows a ComboBox)?

@w-ahmad
Comment options

This is just an example: my answer was that you can use dictionaries to bind data in TableView, meaning any dictionary with a key type supported by WinUI for binding. I believe it only supports int and string keys.

@Rafucho25
Comment options

My problem was that the option Auto-generating Columns doesn't work with dictionaries or ExpandoObject, so I fixed it by creating the columns manually. Thanks for your help.

Answer selected by Rafucho25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.