在Silverlight中,DataGrid、Listbox等控件与数据(List<T>或ObservableCollection<T>)绑定后,当数据发生更新后,之前选中行的视觉效果将消失掉。如要始终把握选中行永久处在其视觉效果下,方法如下:

  选中项改变时记录其位置:

    private int pos = -1;
        private void MainListBox_SelectionChanged(object senderSelectionChangedEventArgs e)
        {
            pos = MainListBox.SelectedIndex;
        }
  数据发生改变之后执行这一行即可:
(this.MainListBox.ItemContainerGenerator.ContainerFromIndex(posas ListBoxItem).Focus();

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2021-08-07
  • 2021-10-03
  • 2021-09-18
  • 2022-12-23
  • 2021-08-22
  • 2021-12-22
猜你喜欢
  • 2021-06-10
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案