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.

ItemsRepeater to search DataTemplates when no ItemTemplate defined

See original GitHub issue

The ItemsRepeater is inconsistent with the other Avalonia controls in that it doesn’t appear to search the DataTemplates collections of its parent controls for a matching DataTemplate for it’s items. Instead it reverts to using ToString() when no ItemTemplate is defined; e.g. <ItemsRepeater Items="{Binding Items}"/>

The similar ItemsControl works as expected using the DataTemplates of its parent controls. <ItemsControl Items="{Binding Items}"/>

I think it would make sense for ItemsRepeater to default to searching the Avalonia DataTemplates collections for a matching template.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
nrenzonicommented, May 8, 2023

This is the behavior from the upstream ItemsRepeater and I’d be hesitant to diverge from the behavior there for a few reasons:

  • It would make future porting of features/fixes from upstream more difficult
  • It would disable element recycling, because we we need to wrap the ItemTemplate in an ElementFactory in order to implement recycling. If we have to search DataTemplates then there can be a different data template for each element

If you want your ItemsRepeater to search DataTemplates then the simplest way is to put a ContentPresenter or ContentControl-derived control in the ItemsRepeater.ItemTemplate property, Note that you may see decreased performance however because only the ContentPresenter can be recycled in this case, and not the content itself.

I’m going to close this issue as by design but please feel free to continue discussion.

Can you share code for how to do this? I have the use case where my ItemsRepeater.Items is a collection of an abstract class type, and I’d like to have different DataTemplates per each concrete class type. I thought I could define the Data Templates in ItemsRepeater.DataTemplates, but it’s not being referenced, similar to this github issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ItemsRepeater - Windows apps
ItemsRepeater is a light-weight control to generate and present a collection of items.
Read more >
ItemsRepeater
A data-driven collection control that incorporates a flexible layout system, custom views, and virtualization.
Read more >
How to use UserControls in an ItemsRepeater for UWP
How to use UserControls in an ItemsRepeater for UWP. You could insert UserControl into ItemsRepeater's ItemTemplate .
Read more >
Introducing WinUI ItemsRepeater and Friends
ItemsRepeater is an ideal host for this: it's a WinUI element that is designed to be used inside custom controls that display collections....
Read more >
Dressing Up Your Data with WPF DataTemplates
Since the ListBox class defines an ItemTemplate property (typed as DataTemplate) and the bound data matches the DataType specified in the DataTemplate, WPF ......
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