Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 7b5ee1c

Browse files
committed
faster delete the sessions from wpf sample app
1 parent 8ac7914 commit 7b5ee1c

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

examples/Titanium.Web.Proxy.Examples.Wpf/MainWindow.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public MainWindow()
101101
InitializeComponent();
102102
}
103103

104-
public ObservableCollection<SessionListItem> Sessions { get; } = new ObservableCollection<SessionListItem>();
104+
public ObservableCollectionEx<SessionListItem> Sessions { get; } = new ObservableCollectionEx<SessionListItem>();
105105

106106
public SessionListItem SelectedSession
107107
{
@@ -280,11 +280,14 @@ private void ListViewSessions_OnKeyDown(object sender, KeyEventArgs e)
280280
if (e.Key == Key.Delete)
281281
{
282282
var selectedItems = ((ListView)sender).SelectedItems;
283+
Sessions.SuppressNotification = true;
283284
foreach (var item in selectedItems.Cast<SessionListItem>().ToArray())
284285
{
285286
Sessions.Remove(item);
286287
sessionDictionary.Remove(item.HttpClient);
287288
}
289+
290+
Sessions.SuppressNotification = false;
288291
}
289292
}
290293

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections.ObjectModel;
2+
using System.Collections.Specialized;
3+
4+
namespace Titanium.Web.Proxy.Examples.Wpf
5+
{
6+
public class ObservableCollectionEx<T> : ObservableCollection<T>
7+
{
8+
private bool notificationSuppressed;
9+
private bool suppressNotification;
10+
11+
public bool SuppressNotification
12+
{
13+
get => suppressNotification;
14+
set
15+
{
16+
suppressNotification = value;
17+
if (suppressNotification == false && notificationSuppressed)
18+
{
19+
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
20+
notificationSuppressed = false;
21+
}
22+
}
23+
}
24+
25+
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
26+
{
27+
if (SuppressNotification)
28+
{
29+
notificationSuppressed = true;
30+
return;
31+
}
32+
33+
base.OnCollectionChanged(e);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)