mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Block Notifychange unless all the element is added into the observablecollection
This should improve the response speed.
This commit is contained in:
parent
e34a52c74e
commit
dab8c5da95
1 changed files with 25 additions and 12 deletions
|
|
@ -260,7 +260,31 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
public class ResultCollection : ObservableCollection<ResultViewModel>, INotifyCollectionChanged
|
||||
{
|
||||
private bool _suppressNotification = false;
|
||||
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (!_suppressNotification)
|
||||
base.OnCollectionChanged(e);
|
||||
}
|
||||
|
||||
public override event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
|
||||
// https://peteohanlon.wordpress.com/2008/10/22/bulk-loading-in-observablecollection/
|
||||
public void AddRange(IEnumerable<ResultViewModel> Items)
|
||||
{
|
||||
_suppressNotification = true;
|
||||
|
||||
foreach (var item in Items)
|
||||
{
|
||||
Add(item);
|
||||
}
|
||||
|
||||
|
||||
// wpf use directx / double buffered already, so just reset all won't cause ui flickering
|
||||
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
return;
|
||||
|
||||
}
|
||||
public void RemoveAll()
|
||||
{
|
||||
ClearItems();
|
||||
|
|
@ -272,20 +296,9 @@ namespace Flow.Launcher.ViewModel
|
|||
/// <param name="newItems"></param>
|
||||
public void Update(List<ResultViewModel> newItems)
|
||||
{
|
||||
|
||||
|
||||
ClearItems();
|
||||
|
||||
foreach (var item in newItems)
|
||||
{
|
||||
Add(item);
|
||||
}
|
||||
|
||||
// wpf use directx / double buffered already, so just reset all won't cause ui flickering
|
||||
CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
|
||||
return;
|
||||
|
||||
AddRange(newItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue