Add TemplatePartAttribute for Controls
See original GitHub issueIs your feature request related to a problem? Please describe.
Named parts in control templates are not always clear to control authors, designers and other IDE tooling.
Describe the solution you’d like
WPF has the TemplatePart attribute used with templated controls. This indicates the named parts of the template, and their type, that are used within code-behind. This information was historically used in designers (Blend) as well as with automated checks to ensure default styles and their templates are complete.
This TemplatePart attribute should be added to avalonia and used for all controls (example from WPF). This should be used for all elements that start with the “PART_” prefix in the name.
[TemplatePart(Name="PART_ContentHost", Type=typeof(FrameworkElement))]
public abstract class TextBoxBase
- Microsoft Docs TemplatePartAttribute
- Template parts and custom controls (quick tip)
- WPF TemplateParts
Describe alternatives you’ve considered
The alternative is no attribute at all as currently exists.
Additional context
Information for PseuodClasses is provided in another attribute. This one should be included as well for completeness.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (6 by maintainers)

Top Related StackOverflow Question
Created ticket in Rider’s YouTrack - https://youtrack.jetbrains.com/issue/RSRP-488276 Though I noticed they did not implemented support for the same attribute in WPF https://youtrack.jetbrains.com/issue/RSRP-330024 .
I wasn’t really thought about code generation, it sounds like a good argument to have this attribute even without support IDE support. Created issue for that https://github.com/AvaloniaUI/Avalonia/issues/11934 Though there is couple of problems what I see there.