-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat: ItemTypeAttribute #13104
base: master
Are you sure you want to change the base?
feat: ItemTypeAttribute #13104
Conversation
You can test this PR using the following package version. |
[ItemType(typeof(ContentControl))] | ||
public class ItemsControl : TemplatedControl, IChildIndexProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ItemsControl can have any types as items. ContentControl is just a default for virtualized containers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ItemType does not add any constraints, it is only used to allow Intellisense to propose the types.
I use this because it is default container that can be used to display an item.
Avalonia/src/Avalonia.Controls/ItemsControl.cs
Lines 338 to 344 in 8ea685e
/// <summary> | |
/// Creates or a container that can be used to display an item. | |
/// </summary> | |
protected internal virtual Control CreateContainerForItemOverride(object? item, int index, object? recycleKey) | |
{ | |
return new ContentPresenter(); | |
} |
[AttributeUsage(AttributeTargets.Class, | ||
AllowMultiple = false, | ||
Inherited = true)] | ||
public sealed class ItemTypeAttribute: DesignerAttribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I am not sure about this PR.
Default controls could be guessed from the naming (ListBox -> ListBoxItem) or hardcoded. When this PR assumes that every custom control will apply this attribute to be efficient. Which is unlikely to be followed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ItemTypeAttribute
is marked Inherited true. So if you create the public class MyFashionListBox:ListBox
, it will inherit the ItemTypeAttribute from the ListBox
. Additionally we could create an analyzer/fixer or create a source generator that parses CreateContainerForItemOverride and generates ItemTypeAttribute.
You can test this PR using the following package version. |
You can test this PR using the following package version. |
You can test this PR using the following package version. |
Part of AvaloniaUI/AvaloniaVS#386
What does the pull request do?
Allow AvaloniaVS Intellisense to identify the item type of
ItemsControl
,ListBox
, etc..What is the current behavior?
AvaloniaVS Intellisense show all class derived from
AvaloniaObject
What is the updated/expected behavior with this PR?
How was the solution implemented (if it's not obvious)?
ItemTypeAttribute indicates AvaloniaVS Intellisense what the base type of the items in the
ListBoxItem
example control is forListBox
.ItemTypeAttribute
derives fromDesignerAttribute
, to allow in the future in a PR to eliminate all the attributes derived fromDesignerAttribute
during the packaging phase and keep them only in the reference assemblies.Checklist
Breaking changes
Obsoletions / Deprecations
Fixed issues