/
TestExplorerControl.xaml.cs
56 lines (48 loc) · 1.63 KB
/
TestExplorerControl.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Windows.Data;
using System.Windows.Threading;
namespace Rubberduck.UI.UnitTesting
{
/// <summary>
/// Interaction logic for TestExplorerControl.xaml
/// </summary>
public partial class TestExplorerControl : IDisposable
{
private readonly Dispatcher _dispatcher;
public TestExplorerControl()
{
InitializeComponent();
DataContextChanged += TestExplorerControl_DataContextChanged;
_dispatcher = Dispatcher.CurrentDispatcher;
}
private void TestExplorerControl_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is TestExplorerViewModel oldContext)
{
oldContext.TestCompleted -= OnTestCompleted;
}
if (e.NewValue is TestExplorerViewModel context)
{
context.TestCompleted += OnTestCompleted;
}
}
private void OnTestCompleted(object sender, EventArgs eventArgs)
{
_dispatcher.Invoke(() =>
{
if (FindResource("ResultsByOutcome") is CollectionViewSource resource)
{
resource.View.Refresh();
}
});
}
private bool _isDisposed;
public void Dispose()
{
if (_isDisposed || DataContext == null) { return; }
DataContextChanged -= TestExplorerControl_DataContextChanged;
((TestExplorerViewModel)DataContext).TestCompleted -= OnTestCompleted;
_isDisposed = true;
}
}
}