我有一个 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>
这里有一个很好的优先绑定(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/