When an `ItemsControl` returns true for `IsItemItsOwnContainer`, `ItemContainerPrepared` should only be called once the first time the container is prepared.
Requires that `ContainerFromIndex` returns `ItemIsOwnContainer` items that have previously been prepared in order for `SelectingItemsControl` to update their selection correctly when outside the realized viewport.
Fixes#11119
`EffectiveViewportChanged` can result in a viewport that is larger than the panel bounds in cases where clipping is not enabled on the parent. Constrain the viewport to the size of the panel.
Try to get an "anchor element" during measure, which is an existing element in the viewport that we know the position of. Start realizing elements from this anchor element.
We need to register controls as anchor candidates in the panel instead of in `ItemsControl` because the candidate needs to be registered after arrange. Consider this scenario:
- In Measure:
- Container is realized and registered as an anchor candidate
- Container is unrealized and unregistered
- Container is recycled and registered, but it is still placed in the position from before it was recycled
- In Arrange:
- The container is placed in its new position
- The `ScrollContentPresenter` sees it's been moved and adjusts the viewport to anchor it
This is obviously incorrect, but was what was happening when `ItemsControl` was responsible for registering anchor candidates.
Instead of tracking which containers have already been registered, change the list of anchor candidates in `ScrollContentPresenter` to a `HashSet` so we can just register it multiple times.
- Before we were clamping indexes too early, meaning that `firstIndexU` was calculated with a non-clamped index
- `_startUUnstable` needs to be set when the remove happens before the realized elements
There's a problem with `DataBox` that I can't repro in a unit test. Add some redundancy such that if we're still waiting for a viewport update after carrying out a layout pass, force another layout.
This necessitated adding another stage to the container preparation lifecycle that will be called after the container is added to the logical and visual trees: `ItemContainerPrepared`. Such a method is going to be necessary anyway if we ever want to expose events for container realization so will probably be worth having regardless.
A lot still broken, in particular virtualization is completely removed.`ItemsPresenter` now no longer has an `Items` or `ItemTemplate` property; it detects when it's hosted in an `ItemsControl`. `IItemsPresenter` interface removed.
Add support for selection wrapping for ListBox, ItemsControl, ComboBox.
Co-authored-by: Steven Kirk <grokys@users.noreply.github.com>
Co-authored-by: Takoooooo <tako0qq@gmail.com>
Co-authored-by: Steven Kirk <grokys@gmail.com>