【问题标题】:Loading more items when scrollbar scrolled to the end in ListView(WPF)当滚动条在 ListView(WPF)中滚动到末尾时加载更多项目
【发布时间】:2013-08-15 19:36:24
【问题描述】:

我想实现一个使用 ListView 加载项目的功能,但是项目的数量非常大,所以我希望当用户滚动滚动条到 ListView 的末尾时,它会自动加载更多的项目。我在这里找到了检测滚动是否滚动到末尾的解决方案:Detect when WPF listview scrollbar is at the bottom? 但是在 MVVM 中,我没有找到传递 EventArgs 的解决方案。还有其他解决方案吗? 我的 Xaml 如下所示:

<ScrollViewer>
<ListView>
    ...
</ListView>
</ScrollViewer>

谢谢!

【问题讨论】:

标签: wpf listview scrollviewer


【解决方案1】:

如果您在 WPF 项目中使用 MVVMLight,只需将 PassEventArgsToCommand 设置为 true。

例如:

xmlns:ni="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:mv="http://www.galasoft.ch/mvvmlight"

<ni:Interaction.Triggers>
<ni:EventTrigger EventName="SelectionChanged">
    <mv:EventToCommand Command="{Binding YourCommand}" PassEventArgsToCommand="True" />
</ni:EventTrigger>

【讨论】:

    【解决方案2】:

    您可以让 View 在 ViewModel 上执行 ICommand 属性,并利用 Execute 方法的 CommandParameter 参数。但是,我会警告说,将 View 的状态传递给 ViewModel 以便 ViewModel 可以确定要加载的项目不是合适的 MVVM 模式。通常,ViewModel 需要驱动显示,即使这包括将一些 UI 状态信息从 View 卸载到 ViewModel,以便它可以本地推断要加载的内容。

    【讨论】:

    • 为什么它必须是 EventArgs 对象?重点不只是将某些状态从 View 传递到 ViewModel 吗? CommandParameter 是 Object 类型 - 所以,事实上,您可以传递 EventArgs。
    猜你喜欢
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多