Question

I'm using custom behavior for scrolling list view item into current visible view of ListView:

mvvm how to make a list view auto scroll to a new Item in a list view

<UserControl.Resources>
    <Style x:Key="ListBoxItemContainerStyle" TargetType="{x:Type ListBoxItem}"
        BasedOn="{StaticResource {x:Type ListBoxItem}}">
        <Setter Property="localBehaviors:ListBoxItemBehavior.IsBroughtIntoViewWhenSelected" Value="true"/>
    </Style>
</UserControl.Resources>

<!-- using Caliburn.Micro's conventions to bind ItemsSource -->
<ListView x:Name="Items" ItemContainerStyle="{StaticResource ListBoxItemContainerStyle}"
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Column #1" DisplayMemberBinding="{Binding ValueOfColumnOne}" />
            <!-- the rest of columns are defined here using DisplayMemberBinding or GridViewColumn.CellTemplate -->
        </GridView
    </ListView.View>
</ListView>

The problem is that as described in this question on SO, list view items lose their display definition (template I guess):

ListView losing GridView display when applying ItemContainerStyle

However, I don't want to redefine template of ListViewItem; i.e. I want to use default, provided by WPF.

Was it helpful?

Solution

Can't you just use the ScrollIntoView? Then focus it.

listview.ScrollIntoView(listviewitem);
listviewitem.Focus();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top