Feature: Source Generator for TemplateSelector #95
michael-hawker
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
This is a neat use of Source Generators, but I'm not sure it's the best way to improve on how we declare and use Template Selectors today. A few issues pop out at me:
Overall, I think there are better ways we could improve on how Template Selectors are declared. I'm a big fan of the XamlTemplateSelector as it makes declaring them much easier, without losing the flexibility they already provide. From XamlTemplateSelector by @djspider117: <xts:XamlTemplateSelector x:Key="MySelector">
<DataTemplate xts:XamlTypeHelper.TargetType="models:YOUR_MODEL_HERE1">...</DataTemplate>
<DataTemplate xts:XamlTypeHelper.TargetType="models:YOUR_MODEL_HERE2">...</DataTemplate>
</xts:XamlTemplateSelector> <ListView Name="lvDemo" ItemTemplateSelector="{StaticResource MySelector}" /> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
DataTemplateSelector and Styler Source Generator
Problem Statement
Creating
DataTemplateSelector
classes is annoying and cumbersome when they're usually pretty simple.Inspiration
I believe Source Generators are playing better with XAML now, so this idea came to mind based on our recent explorations with SG in Labs itself and a discussion in Discord (and some prior thoughts we've talked about in the past on this subject).
Proposed Solution
Would probably need some more investigation, but was just wondering if we could take the MVVM Toolkit style approach of just decorating a method closer to where things would be used:
Also see Alternate Proposal below in Open Questions
Generated code:
Open Questions
StaticResource
directly...?API Reference Docs
References
Beta Was this translation helpful? Give feedback.
All reactions