Automatic Scrolling in a Silverlight List Box

前端 未结 4 1250
情歌与酒
情歌与酒 2020-12-18 21:46

How can I programmatically force a silverlight list box to scroll to the bottom so that the last item added is always visible.

I\'ve tried simply selecting the item

4条回答
  •  鱼传尺愫
    2020-12-18 22:21

    Just went through this and none of the solutions above worked in a Silverlight 5 app. The solution turned out to be this:

     public void ScrollSelectedItemIntoView(object item)
     {
          if (item != null)
          {                
              FrameworkElement frameworkElement = listbox.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
              if (frameworkElement != null)
              {
                  var scrollHost = listbox.GetScrollHost();                    
                  scrollHost.ScrollIntoView(frameworkElement);
              }
          }                
     }
    

提交回复
热议问题