I have one UserControl which has a ListView showing a list of Client objects. Double clicking one of the rows plays an animation and transitions to another UserControl which shows the list of accounts for that client.
我有一个UserControl,它有一个显示Client对象列表的ListView。双击其中一行将播放动画并转换到另一个UserControl,该控件显示该客户端的帐户列表。
The second user control is bound to the Accounts property on the Client object. The list of accounts is loaded the first time the property is accessed. This all works great if the list of accounts is small. If the list of accounts is large, there is a very noticeable delay between double clicking and the list of accounts appearing. And the animation doesn't play at all.
第二个用户控件绑定到Client对象上的Accounts属性。帐户列表在第一次访问该属性时加载。如果帐户列表很小,这一切都很有效。如果帐户列表很大,则双击和出现的帐户列表之间会有明显的延迟。并且动画根本不播放。
I understand what's going on here, but I'm not sure of the best way to fix it. How would I make it so that the animation still plays and the second user control is shown, but the list of accounts appears as they're loaded? I understand I'm going to need to load the list view asynchronously, and I have no problem using a BackgroundWorker for this, but I'm not sure where this loading would happen.
我理解这里发生了什么,但我不确定解决它的最佳方法。如何制作动画以便动画仍然播放并显示第二个用户控件,但是会在加载时显示帐户列表?我知道我需要异步加载列表视图,使用BackgroundWorker我没有问题,但我不确定这种加载会发生在哪里。
The list of accounts is an ObservableCollection, and the Client object implements INotifyPropertyChanged, however doesn't call PropertyChanged for the accounts property because it doesn't have a setter.
帐户列表是ObservableCollection,Client对象实现INotifyPropertyChanged,但不会为accounts属性调用PropertyChanged,因为它没有setter。
2 个解决方案
#1
I think you need to look at the Virtualized controls in WPF - these only display the contents required not the whole list and are therefore a lot faster than the standard ListView.
我认为您需要查看WPF中的虚拟化控件 - 这些控件只显示所需内容而不是整个列表,因此比标准ListView快得多。
#2
You can try and set IsAsync=true on the binding, for example: {Binding Path=Accouns, IsAsync=true}
您可以尝试在绑定上设置IsAsync = true,例如:{Binding Path = Accouns,IsAsync = true}
#1
I think you need to look at the Virtualized controls in WPF - these only display the contents required not the whole list and are therefore a lot faster than the standard ListView.
我认为您需要查看WPF中的虚拟化控件 - 这些控件只显示所需内容而不是整个列表,因此比标准ListView快得多。
#2
You can try and set IsAsync=true on the binding, for example: {Binding Path=Accouns, IsAsync=true}
您可以尝试在绑定上设置IsAsync = true,例如:{Binding Path = Accouns,IsAsync = true}