我使用下面的代码使用MVVM绑定我的listBox SelectedItem。但是,该项目已被选中,但它不会滚动到所选项目。
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}"
页面加载中的代码
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);
}
非常烦人,当我调试代码时,该事件被选中,但它不会滚动到所选的索引或项目。
谢谢!
答案 0 :(得分:0)
好像你ScrollIntoView
:
How to Scroll into selected item in listbox in windows phone 7