代码之家  ›  专栏  ›  技术社区  ›  Geeth

如何从列表框WPF获取列表框项

  •  1
  • Geeth  · 技术社区  · 14 年前

    我想滚动列表框,该列表框根据其选择放置在srollviewer中。

     ListBoxItem item = (ListBoxItem)(lbTrack.ItemContainerGenerator.ContainerFromItem(lbTrack.Items.CurrentItem));
    
           // ListBoxItem item = (ListBoxItem)(lbTrack.ItemContainerGenerator.ContainerFromItem(lbTrack.SelectedItem));
            if (item != null)
            {
                item.BringIntoView();
            }
    

    但它给出了空值。

    2 回复  |  直到 14 年前
        1
  •  1
  •   Eugene Cheverda    14 年前

    希望这有助于:

    if (listView.SelectedItem != null)
    {
       listView.ScrollIntoView(listView.SelectedItem);
    }
    
        2
  •  0
  •   Ragunathan    14 年前

    尝试下面的代码

      Dispatcher.CurrentDispatcher.BeginInvoke((ThreadStart)delegate
      {
          item.BringToView();
       }, DispatcherPriority.Normal, null);