indexingdisplaywinui-3scrollviewerwinui

How scroll to spesific item in ItemsRepeater by index in WinUI 3


I have itemsRepeater of images of type BitmapImage, and itemsRepeater exist in ScrollViewer. and I want that user input number and scroll to the image that in this index in ItemsRepeater. How I do it in WinUI 3 search and display image by index?

I try this in .xaml.cs:

scroll.ChangeView(null, pageIndex * (ViewModel.Pages.FirstOrDefault().PixelHeight), null);

but this not corect , for example I input 10 and this scroll to 12. I also try this:


var container = PdfImageRepeater.TryGetElement(pageIndex);
if (container != null)
    container.StartBringIntoView();

but container always null. What can I do?


Solution

  • Try the following:

    var pageItem = PdfImageRepeater.GetOrCreateElement(pageIndex);
    pageItem.UpdateLayout();
    pageItem.StartBringIntoView();