WPF ListView Ever focused on the last item added?

I have many ListViews with the same DataSource, IsSynchronizedWithCurrentItem="True" and I am dynamically adding items to this data source.

The problem arises when scrolls appear, the added elements are not displayed if I have not moved the scroll bar. Should I use a different control for this purpose .. or how can I display the last added item (and scroll bars).

So far, I have done everything directly in XAML, so I would appreciate such a solution, if possible.

+5
source share
4 answers

I came up with a solution:

, !

, Listroll ScrollBars ScrollViewer.

...

<Grid>
    <Grid.RowDefinitions>
       <RowDefinition Height="*" />  <!-- This is needed! -->
       ...
    </Grid.RowDefinitions>

..

<ScrollViewer x:Name="MyScrollViewer" Grid.Row="0" >
            <ListView Name="MyListView" 
                      ItemsSource="{Binding}" 
                      IsSynchronizedWithCurrentItem="True"
                      ScrollViewer.VerticalScrollBarVisibility="Disabled" />
</ScrollViewer>

...

</Grid>

MyScrollViewer.ScrollToEnd();
+1

, :

ListView.ScrollIntoView(ListView.SelectedItem);
+2
if ( !(myListView.Items.IsEmpty) )
{
    myListView.ScrollIntoView(myListView.Items[myListView.Items.Count - 1]);
}

, !

+1

, , ListView.BringIntoView(), ... :).

0

All Articles