tags:

views:

433

answers:

4

Hi!

I have many ListViews with the same DataSource with IsSynchronizedWithCurrentItem="True" and I'm dynamicaly adding items to this DataSource.

The problem ist when the scrolls appears, the added items are not visible unless I move the scrollbar. Should I use another Control for this purpose.. or how can bring the last added item into view (and scrollbars).

Until now I was doing everything directly in XAML, so I'd appreciate such a solution if possible.

+1  A: 

I come with a solution:

It cannot be applied in all cases, but it this one it's sufficient!

The trick is to disable the ListView ScrollBars and surround it with the 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>

Then simply if needed call

MyScrollViewer.ScrollToEnd();
PaN1C_Showt1Me
A: 

That sounds suspicious, but even if it's true, you can always call ListView.BringIntoView() method, to... bring selected item into view :).

Anvaka
Yeah.. you're right, but you have to write a bit more code to select the last item and bring it into view.. but it's a possibility too
PaN1C_Showt1Me
+1  A: 

I think you may need to use the method:

ListView.ScrollIntoView(ListView.SelectedItem);
Sam Meldrum
A: 
if ( !(myListView.Items.IsEmpty) )
{
    myListView.ScrollIntoView(myListView.Items[myListView.Items.Count - 1]);
}

Hope that helps!

Veer