0

I am using below code to bind my listBox SelectedItem using MVVM. However the item is selected but it doesn't scroll to the selected item.

public int CollectedItem
        {
            get { return _collectedItem; }
            set
            {
                if (value == _collectedItem)
                    return;

                _collectedItem = value;
                OnPropertyChanged("CollectedItem");
                SelectedItem = ChapterContent.Find(x => x.ArabicText.AyaID == _collectedItem);
            }
        }
        public ArabicTextWithTranslation SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                if (value != _selectedItem)
                    _selectedItem = value;
                OnPropertyChanged("SelectedItem");
            }

        }

XAML Page

<ListBox x:Name="lsbReadingChapter" ItemsSource="{Binding ChapterContent}" SelectedItem="{Binding SelectedItem}"

Code behind in Page Load

void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            (DataContext as MainChapaterViewModel).CollectedItem = 10;
            this.lsbReadingChapter.SelectedIndex = lsbReadingChapter.Items.Count - 1;
            this.lsbReadingChapter.UpdateLayout();
            this.lsbReadingChapter.ScrollIntoView(lsbReadingChapter.SelectedIndex);

            this.lsbReadingChapter.SelectedIndex = 10;
            this.lsbReadingChapter.UpdateLayout();
            this.lsbReadingChapter.ScrollIntoView(10);

            //scrollIntoSelectedItem(lsbReadingChapter.SelectedIndex);
        } 

It's very annoying, The item is selected as the event occurs when I debug the code, but it doesn't scroll to the selected index or item.

Thanks!

ARH
  • 1,566
  • 3
  • 25
  • 56
  • Read this article http://stackoverflow.com/questions/8827489/scroll-wpf-listbox-to-the-selecteditem-set-in-code-in-a-view-model – Yuri Dorokhov Feb 14 '15 at 18:33

1 Answers1

0

Seems like you're going wrong with the ScrollIntoView:

How to Scroll into selected item in listbox in windows phone 7

Reference: Scroll to bottom of listbox wp7

Community
  • 1
  • 1
Kulasangar
  • 9,046
  • 5
  • 51
  • 82