异步加载数据时的反馈

use*_*225 1 c# data-binding wpf asynchronous .net-4.0

我有一个ComboBox,其ItemsSource绑定到一个ObjectAsProvider,其IsAsynchronous属性设置为true.在加载数据的方法中,我放置了等待10秒,以模拟此数据的长加载时间.

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

我想在10秒的等待时间内提醒用户这个特定的ComboBox正在加载数据.类似于控件背景中的progressBar,仅在某个'isLoading'属性或任何设置为true时启用.有可能做到这一点吗?

谢谢.

pun*_*r76 6

这看起来像优先绑定可能是一个解决方案

<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>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

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

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

希望这可以帮助