Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

BringIntoView() calls on elements inside an ItemsRepeater within ItemsRepeaterScrollHost fail to scroll the element into view. The RequestBringIntoView event bubbles from child elements but never reaches the scroll host because ItemsRepeater doesn't handle it.

Changes

  • Override OnRequestBringIntoView in ItemsRepeater.wpf.cs

    • Intercepts BringIntoView requests from descendant elements
    • Walks visual tree to find ancestor ItemsRepeaterScrollHost
    • Forwards to scrollHost.StartBringIntoView() with default alignment (0.0, 0.0)
    • Falls back to base implementation if no scroll host exists
  • Add IsAncestorOf helper

    • Verifies target element is actually a descendant before handling
    • Prevents cross-control interference

Example Usage

// Get element at index 50 (may be virtualized)
var element = itemsRepeater.TryGetElement(50) ?? itemsRepeater.GetOrCreateElement(50);

// Now works correctly with ItemsRepeaterScrollHost + UniformGridLayout
element.BringIntoView();

Works with all layouts (UniformGridLayout, StackLayout, FlowLayout) and both realized/unrealized elements. No breaking changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>BringIntoView doesn't work in ItemsRepeater inside ItemsRepeaterScrollHost (UniformGridLayout)</issue_title>
<issue_description>### Describe the bug

item.BringIntoView doesn't work in ItemsRepeater inside ItemsRepeaterScrollHost (UniformGridLayout)

<ui:ItemsRepeaterScrollHost>
    <ui:ScrollViewerEx x:Name="scrollViewer" Padding="0,0,16,0">
        <ui:ItemsRepeater

...
ui:ItemsRepeater.Layout
<ui:UniformGridLayout />
</ui:ItemsRepeater.Layout>

Following code doesn't work due to virtualization.

FrameworkElement element = itemsRepeater.GetOrCreateElement(selectedItemIndex.Value) as FrameworkElement;
element .BringIntoView();

Waiting for item LayoutUpdated before calling BringIntoView works better, but only if there is only one column of items.

Please provide a way to make an item visible with ItemsRepeater

Reproduction

See description

Suggested Solution

No response

Library Version

0.10.2

Operating System

Windows 11

Framework

.NET Framework

Framework Version

4.7

Source of Package

Self-Compiled

Additional Notes

No response

Validations

  • Check that there isn't already an issue that reports the same or similar problem.
  • Check that this is a bug in the library that should be fixed, not a feature, also this is not about the documentation. (Or please choose the right repo and template.)
  • This is one single problem, or a few problems with the same cause. (If you want to report multiple problems, please create one issue for every single problem.)
  • You've checked that this problem still exists in the latest version. (Keep in mind that we don't provide any support for old versions.)
  • You know that we can't guarantee that we will satisfy your request. This is not really our duty to do everything anyone asks for. Also, you will treat our staff, contributors, and other users with respect and kindness.
  • You're sure there's something wrong with the library itself, not how you're using it. (If you are having issues using it and need help, please go to discussion.)</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits December 16, 2025 13:38
- Override OnRequestBringIntoView in ItemsRepeater to intercept BringIntoView calls
- Forward the request to ItemsRepeaterScrollHost.StartBringIntoView() when available
- This enables BringIntoView to work properly with virtualized layouts like UniformGridLayout

Co-authored-by: NotYoojun <54567489+NotYoojun@users.noreply.github.com>
- Add IsAncestorOf helper method to verify target element is a descendant
- Only handle BringIntoView for elements that are actually within this ItemsRepeater
- Ensures proper event handling and avoids interfering with other controls

Co-authored-by: NotYoojun <54567489+NotYoojun@users.noreply.github.com>
- Add DefaultBringIntoViewAlignment constant (0.0 for top/left alignment)
- Add DefaultBringIntoViewOffset constant (0.0 for no offset)
- Add DefaultBringIntoViewAnimate constant (false for immediate scrolling)
- Improves code readability and maintainability

Co-authored-by: NotYoojun <54567489+NotYoojun@users.noreply.github.com>
- Add using directive for System.Windows.Media namespace
- Simplify targetElement declaration by combining with pattern matching
- Improves code readability and follows codebase conventions

Co-authored-by: NotYoojun <54567489+NotYoojun@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix BringIntoView functionality in ItemsRepeater Fix BringIntoView for ItemsRepeater in ItemsRepeaterScrollHost Dec 16, 2025
Copilot AI requested a review from NotYoojun December 16, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BringIntoView doesn't work in ItemsRepeater inside ItemsRepeaterScrollHost (UniformGridLayout)

2 participants