c# - 异步加载数据时的反馈

标签 c# wpf data-binding .net-4.0 asynchronous

我有一个 ComboBox,其 ItemsSource 绑定(bind)到一个 ObjectDataProvider,该 ObjectDataProvider 的 IsAsynchronous 属性设置为 true。在加载数据的方法中,我等待 10 秒,以模拟此数据的长时间加载。

异步加载效果很好 - 整个窗口仍然响应,10 秒后我看到 ComboBox 下拉列表已填充。

在 10 秒的等待时间内,我想提醒用户这个特定的 ComboBox 正在加载数据。类似于控件背景中的进度条,仅当某个“isLoading”属性或任何设置为 true 时才启用。有可能实现吗?

谢谢。

最佳答案

这看起来像 Priority Binding 可能是您的解决方案

<ListBox>
    <ListBox.ItemsSource>
    <PriorityBinding>
        <!-- highest priority sources are first in the list -->
        <Binding Path="LongLoadingCollection" IsAsync="True" />
        <!-- this contains only one item like "loading data..." -->
        <Binding Path="LoadMessage" IsAsync="True" />
    </PriorityBinding>
    </ListBox.ItemsSource>
</ListBox>

enter image description here

这里有一个很好的优先绑定(bind)教程
http://www.switchonthecode.com/tutorials/wpf-tutorial-priority-bindings

或者看看msdn
http://msdn.microsoft.com/en-us/library/system.windows.data.prioritybinding.aspx

希望对你有帮助

关于c# - 异步加载数据时的反馈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8450416/

相关文章:

c# - 使用 ToArgb() 后跟 FromArgb() 不会产生原始颜色

c# - 是否可以使用 WCF 架构每天处理 1B 请求?

c# - 如何判断拖放操作是否失败?

wpf - 测量 WPF 数据绑定(bind)处理的时间

c# - 项目模板中的 <%# DataBinder.Eval(Container.DataItem ,"ColumnName") %> 究竟做了什么?

c# - 是否总是从函数返回新列表?

c# - 如何使用 Word Automation 获取页面范围

c# - WPF Prism + 现有 WPF 应用程序

c# - 整行的 WPF TreeView 项目背景

wpf - 根据匹配对象在 XAML 中设置 ComboBox.SelectedItem