-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMainWindow.LiveSearch.cs
More file actions
59 lines (49 loc) · 1.77 KB
/
Copy pathMainWindow.LiveSearch.cs
File metadata and controls
59 lines (49 loc) · 1.77 KB
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
57
58
59
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using ArIED61850Tester.Models;
namespace ArIED61850Tester;
public partial class MainWindow
{
private void ExplorerLiveSearch_TextChanged(object sender, TextChangedEventArgs e)
=> ApplyExplorerLiveSearchFilter();
private void ExplorerLiveSearchClear_Click(object sender, RoutedEventArgs e)
{
if (ExplorerLiveSearchBox == null)
return;
ExplorerLiveSearchBox.Clear();
ExplorerLiveSearchBox.Focus();
}
private void ApplyExplorerLiveSearchFilter()
{
var device = SelectedDevice;
if (device == null)
return;
var view = CollectionViewSource.GetDefaultView(device.Points);
if (view == null || !view.CanFilter)
return;
var query = ExplorerLiveSearchBox?.Text?.Trim() ?? string.Empty;
if (query.Length == 0)
{
view.Filter = null;
view.Refresh();
return;
}
view.Filter = item =>
{
if (item is not Iec61850MonitorPoint point)
return false;
return Contains(point.SignalName, query) ||
Contains(point.IecTelegram, query) ||
Contains(point.IecReference, query) ||
Contains(point.DisplayValue, query) ||
Contains(point.Quality, query) ||
Contains(point.SourceMode, query) ||
Contains(point.Category, query) ||
Contains(point.IecDataType, query);
};
view.Refresh();
}
private static bool Contains(string? value, string query)
=> !string.IsNullOrWhiteSpace(value) && value.Contains(query, StringComparison.OrdinalIgnoreCase);
}