Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TemplatePartAttribute for Controls #7432

Closed
robloo opened this issue Jan 25, 2022 · 6 comments · Fixed by #7854
Closed

Add TemplatePartAttribute for Controls #7432

robloo opened this issue Jan 25, 2022 · 6 comments · Fixed by #7854

Comments

@robloo
Copy link
Contributor

robloo commented Jan 25, 2022

Is 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

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.

@robloo
Copy link
Contributor Author

robloo commented Mar 13, 2022

WinUI is now doing something interesting with template parts. Enums are generated for the named parts and then 'magic' strings are removed from code usage.

First example I saw: https://github.com/microsoft/microsoft-ui-xaml/blob/2a6d2d69c809c141ca7916c9730fd5305487501e/dev/TeachingTip/TeachingTipTemplatePartHelpers.h

@maxkatz6
Copy link
Member

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 #11934
Though there is couple of problems what I see there.

@robloo
Copy link
Contributor Author

robloo commented Mar 23, 2022

I wasn't really thought about code generation

Neither did I until I noticed what WinUI is doing recently.

@maxkatz6
Copy link
Member

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 .

@robloo
Copy link
Contributor Author

robloo commented Mar 28, 2022

Though I noticed they did not implemented support for the same attribute in WPF

Well, WPF has been on life support for years now. I can understand they didn't want to invest much. I was already surprised they did full Avalonia support so this has a better chance in my opinion.

Separately, I'll probably add the attributes for all templated controls with a style XAML file next weekend. I imagine I'm going to find naming issues as well (missing PART_ prefix) and we'll have to discuss if a breaking change is worth it. 11.0 is the best time to do this though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants