silverlight - 以编程方式滚动 Silverlight 列表框

标签 silverlight listbox scroll

我尝试使用以下方法,但它似乎不适用于数据绑定(bind)列表框。

 mylistbox.ScrollIntoView(mylistbox.Items[mylistbox.Items.Count - 1])

我也试图捕获 IScrollProvider 但没有成功:
var lbItemAutomation = (ListBoxAutomationPeer)ListBoxAutomationPeer.CreatePeerForElement(mylistbox);
var listBoxScroller = (IScrollProvider)lbItemAutomation.GetPattern(PatternInterface.Scroll);  <-- returns null value

谢谢,
瑞奇

更新 4/1:
重试后,我确认第一种方法有效。但是,获取第二种方法会很好,因为您可以通过此方法按百分比滚动。因此,任何帮助将不胜感激。

最佳答案

我工作得很好:

<StackPanel Orientation="Horizontal">

    <ListBox x:Name="_lbx" ItemsSource="{Binding SimpleItems}" Height="100"/>
    <Button Content="Scroll" Click="DoScroll" />
</StackPanel>

代码隐藏:

在构造函数中:
SimpleItems = new List<string>{ "hello", "world", "the world", "is coming", "to an end", "in 2012", "or maybe", "sometime", "in the future"};

DataContext = this;

然后:
public List<string> SimpleItems { get; set; }


private void DoScroll(object sender, RoutedEventArgs e) {

    _lbx.ScrollIntoView(_lbx.Items[_lbx.Items.Count - 1]);
}

你能发布你相关的 XAML 和代码隐藏吗?

关于silverlight - 以编程方式滚动 Silverlight 列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2563491/

相关文章:

silverlight - 如何在 Silverlight 中播放 ogg vorbis 文件?

WPF ListBox - 如何从数据表中输入值?

java - .NET ListBox 的 Swing 等价物

java - 添加 JPanel 时 JScrollPane 不滚动

c# - 使用 LINQ 的唯一项目列表

c# - 基于网络的 Powerpoint 编辑器和播放器

c# - Setter 在构造函数之前调用

c# - 设置Listbox的滚动条位置

javascript - 支持 Canvas 上的滚动和拖动操作

javascript - 如何在 Slick.js 中使用鼠标滚动而不是拖动?