-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPopupEnumFilter.xaml.cs
90 lines (75 loc) · 2.96 KB
/
PopupEnumFilter.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using DataGridExtensions;
using System;
using System.Windows;
namespace WPF_dnscrypt_proxy_md
{
/// <summary>
/// Interaction logic for PopupEnumFilter.xaml
/// </summary>
public partial class PopupEnumFilter
{
public PopupEnumFilter()
{
InitializeComponent();
}
public int? FlagsValue
{
get { return (int?)GetValue(FlagsValueProperty); }
set { SetValue(FlagsValueProperty, value); }
}
/// <summary>
/// Identifies the Value dependency property
/// </summary>
public static readonly DependencyProperty FlagsValueProperty = DependencyProperty.Register("FlagsValue", typeof(int?), typeof(PopupEnumFilter)
, new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (sender, e) => ((PopupEnumFilter)sender).FlagsValue_Changed()));
public int? ProtocolValue
{
get { return (int?)GetValue(ProtocolValueProperty); }
set { SetValue(ProtocolValueProperty, value); }
}
/// <summary>
/// Identifies the Value dependency property
/// </summary>
public static readonly DependencyProperty ProtocolValueProperty = DependencyProperty.Register("ProtocolValue", typeof(int?), typeof(PopupEnumFilter)
, new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (sender, e) => ((PopupEnumFilter)sender).ProtocolValue_Changed()));
public IContentFilter Filter
{
get { return (IContentFilter)GetValue(FilterProperty); }
set { SetValue(FilterProperty, value); }
}
/// <summary>
/// Identifies the Filter dependency property
/// </summary>
public static readonly DependencyProperty FilterProperty =
DependencyProperty.Register("Filter", typeof(IContentFilter), typeof(PopupEnumFilter), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
private void FlagsValue_Changed()
{
Filter = FlagsValue.HasValue ? new ContentFilter(FlagsValue, true) : null;
}
private void ProtocolValue_Changed()
{
Filter = ProtocolValue.HasValue ? new ContentFilter(ProtocolValue, false) : null;
}
class ContentFilter : IContentFilter
{
private readonly int? _val;
bool Flags { get; set; }
public ContentFilter(int? value, bool flags)
{
_val = value;
Flags = flags;
}
public int? Value
{
get
{
return _val;
}
}
public bool IsMatch(object value)
{
return value==null?false: Flags?(Convert.ToInt32(value)&Value) == Value: Convert.ToInt32(value) == Value;
}
}
}
}