Try ListView.ScrollIntoView() or ListView.MakeVisible first scroll the element container in the view and work on it may be virtualized from the user interface. Then use ListView.ItemContainerGenerator . ContainerFromIndex () to get the container of the item, and then VisualTreeHelper to get its position relative to the ScrollViewer . Then scroll the scrollviewer over the calculated offset.
* EDIT - An example of positioning logic:
Get VisualTreeHelperExtensions from the WinRT XAML Toolkit to access ScrollViewer easily using the GetFirstDescendantOfType() extension method, which transfers some calls to VisualTreeHelper .
Xaml
<Page x:Class="ListViewItemCentering.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:ListViewItemCentering" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <ListView x:Name="listView"> <ListView.ItemTemplate> <DataTemplate> <Border Width="400" Height="100"> <ContentControl Content="{Binding}" FontSize="48" Padding="20,10"/> </Border> </DataTemplate> </ListView.ItemTemplate> </ListView> <Button Content="Skip" Width="200" Height="100" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="ButtonBase_OnClick"/> </Grid> </Page>
WITH#
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Windows.Foundation; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using WinRTXamlToolkit.Controls.Extensions; namespace ListViewItemCentering {
source share