-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
WIP: Support heterogeneous item containers. #11068
Conversation
You can test this PR using the following package version. |
After reviewing the changes in the pull request, overall I like the direction it’s headed. The API updates in the PR allow for multiple known “container” control types to be used for an But what happens when the WPF Technique to Pass the Item to GetContainerForItemOverrideOur WPF products also use the technique described in this comment under their WPF Augmenting that Technique with an ItemContainerTemplateSelectorOur new WPF Bars product makes extensive use of that technique and even augments it to use a WPF Native WPF MenuItem Example of ThisLet me walk through how it works with
Bars Controls ExampleNow let's look at our Bars controls. We offer a And best of all, the generated "container" controls are added directly as children of the Here's an example of our main And here is the XAML file that includes all the ItemContainerTemplates called into by the selector: SummaryYou can see how it's easy to set up any control to be bound to any view model with this technique. And it's fully extensible by the developer customer without them ever inheriting our controls and overriding methods. It would be great if this kind of thing could be supported in Avalonia somehow too. We are happy to discuss further and answer any questions you have about our implementation. |
Thanks for your feedback @billhenn - I'm going to think about this for a few days and tweak the API a little I hope. |
I'm working on a new API, which will be best introduced in a separate PR, so I'll close this PR and link to it in the new PR for context. |
What does the pull request do?
As described in #9497 (comment) - we really need to support heterogeneous item containers, i.e. more than one type of item container in a single
ItemsControl
, with recycling.This isn't supported by the WPF API that we moved to in #9677: although something can be hacked to work in WPF, it can never work with recycling, which means that as soon as we move to a WPF-like API, we now have to move away from it.
The main change in this PR is that the
IsItemItsOwnContainer
API has changed to the following:Where
ItemContainerType
is an opaque type that represents the type of container desired by theItemsControl
for a particular item. There are two inbuiltItemContainerType
s:ItemContainerType.ItemIsOwnContainer
signals that the item should be its own container, and as such as the replacement for theIsItemItsOwnContainer
APIItemContainerType.Default
is returned byItemControl
s which only support a single containerThe new process for generating containers now goes like this:
GetContainerTypeForItem(object)
is called to get the container type for the item. If the returned value isItemContainerType.ItemIsOwnContainer
then the item itself should be used as a container.ItemContainerType
returned fromGetContainerTypeForItem(object)
should be passed toCreateContainer(ItemContainerType)
to create a new container.PrepareItemContainer
,AddInternalChild
andItemContainerPrepared
should be called as beforeWhen it comes time to recycle the container, it should be placed in a pool which is keyed on the
ItemContainerType
.I chose to merge
IsItemItsOwnContainer
intoGetContainerTypeForItem
into a single method to avoid more virtual method calls than necessary when generating containers, even if this means we diverge more from the WPF API.Feedback welcome!
Example
An example of a simple list box which supports multiple container types. First, the list box and the containers:
Models:
Initialization:
Breaking changes
Changes an API that had already undergone a breaking change, so none technically.