2012-08-30 57 views

回答

-1

有一个在Silverlight ListBox

没有名为 “ScrollToBottom” 的方法试试这个:

myListBox.ScrollIntoView(myListBox.Items.Count); 
0

试试这个:

myListBox.ScrollIntoView(myListBox.Items.Count);

如果您的列表框项目是一个控件,上述不会工作,原因是这滚动到项目的顶部而不是底部。

0

This Works。将ListBox设置为不滚动,然后在其周围添加一个ScrollViewer。现在在你的代码背后,你可以将ScrollViewer设置为任何你想要的。

XAML:

<!--Disable the ListBox scroll and add a ScrollViewer so we have control over the scroll position.--> 
    <ScrollViewer 
      Name="scrlvwrListBoxMessages" 
      VerticalScrollBarVisibility="Auto" > 
     <ListBox x:Name="lstbxMessages" 
      ScrollViewer.VerticalScrollBarVisibility="Disabled" > 
</ListBox> 
</ScrollViewer> 

代码:

private void ScrollToBottom() 
    { 
     //Scroll to the bottom. 
     Dispatcher.BeginInvoke(() => 
     { 
      this.scrlvwrListBoxMessages.ScrollToVerticalOffset(double.MaxValue); 
     }); 
    } 
相关问题