Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:03:21+00:00 2026-06-01T21:03:21+00:00

I have an ObservableCollection in the VM that is displayed in the view in

  • 0

I have an ObservableCollection in the VM that is displayed in the view in a ListView. When the selected item changes, the SelectionChanged event fires nicely. Below is how I have the ListView configured:

<ListView Grid.Row="3" Margin="5" AlternationCount="2" Name="_lvSettings" 
          IsSynchronizedWithCurrentItem="True"
          ItemsSource="{Binding Path=CollectionView}" 
          SelectedIndex="{Binding Path=SelectedSettingIndex}"
          SelectionChanged="OnSelectionChanged"  >
    <ListView.View>
        <GridView>
            <GridViewColumn Width="170" 
                            Header="{Binding Path=ShowAllDisplay}"
                            x:Name="_colSettings"  
                            DisplayMemberBinding="{Binding Path=Setting}"/>
            <GridViewColumn Header="Old Value" Width="150" 
                            DisplayMemberBinding="{Binding Path=OldVal}"/>
            <GridViewColumn Header="New Value" 
                            DisplayMemberBinding="{Binding Path=NewVal}" />
        </GridView>
    </ListView.View>
</ListView>

The problem I have is when I change the filter on the collection. The selected item remains the same, which is good, but the ListView changes to display from the first item, and often the selected item is out of view (but still the selected item).

In the VM, I have the property “SelectedSettingIndex” that throws the PropertyChanged event when it changes. Even if I raise the event myself manually (base.OnPropertyChanged(“SelectedSettingIndex”);) from the VM when the filter changes, the event does not seem to really get raised as the property did not really change. There must be a way to call ScrollIntoView or something similar in this scenario, but I can’t figure out the correct event or trigger to do so. What is it that I am missing?

EDIT

Here is a, hopefully better, description of the issue I am concerned with:

1) I am using a CollectionViewSource in the VM to filter data.

2) There is a button for the user to toggle between a filter.

3) Lets assume the ListView has room to show up to 10 items at any given time.

4) The user selects item “A” in the filtered view which is at index 50 in the listview.

5) The user then clicks the button to turn filtering off.

Expected Results: The ListView is populated with the unfiltered list, Item “A” remains selected, and the ListView is “scrolled” such that item “A” is still visible.

Actual Results: The ListView is populated with the unfiltered list, Item “A” remains selected, and the ListView is “scrolled” to the top and showing the first 10 items. Item “A” is not in view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:03:22+00:00Added an answer on June 1, 2026 at 9:03 pm

    Keep the SelectedItem of your ListView in a property:

    public MyTypeOfObject SelectedItem { get; set; }
    

    Assign the binding to XAML:

    <ListView Name="MyListView" SelectedItem="{Binding SelectedItem}"...></ListView>
    

    Now whenever you change filter do:

    if (SelectedItem != null)
        MyListView.ScrollIntoView(SelectedItem);
    

    EDIT:

    To do it in your user control, in order to leave you view model clean from control references (ListView), catch a standard CollectionView event there or define your own that will be fired after filter or other job happened.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that I am populating with items from an ObservableCollection .
I have a ListBox, that's bound to an ObservableCollection . Each ListBoxItem is displayed
I have an ObservableCollection of addresses that I am binding to a ListBox. Then
I have a combobox that is binding to an ObservableCollection of strings in an
I have a ComboBox that is databound to an ObservableCollection of strings . The
I have a WPF ItemsControl that is bound to an ObservableCollection. The XAML: <ItemsControl
In my viewmodel, I have a list (ObservableCollection) containing items. In the view, this
in my Silverlight 4 Application I have an ObservableCollection that I data bind to
I have a TreeView that is bound to an ObservableCollection in my ViewModel. I
In a MVVM WPF application, I have a master-detail View that is used to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.