-
Notifications
You must be signed in to change notification settings - Fork 0
/
BigIntegerUpDown.xaml.vb
240 lines (176 loc) · 6.29 KB
/
BigIntegerUpDown.xaml.vb
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports System.Numerics
Imports System.Globalization
Imports System.Windows.Media.TextFormatting
Imports System.Text.RegularExpressions
Public Class BigIntegerUpDown
Inherits UserControl
Implements INotifyPropertyChanged
#Region "Fields"
Public Delegate Sub ValueChangedEventHandler(sender As Object, e As ValueChangedEventArgs)
Public Event ValueChanged As ValueChangedEventHandler
Public Custom Event ValChanged As ValueChangedEventHandler
AddHandler(ByVal value As ValueChangedEventHandler)
End AddHandler
RemoveHandler(ByVal value As ValueChangedEventHandler)
End RemoveHandler
RaiseEvent(ByVal sender As Object, ByVal e As ValueChangedEventArgs)
End RaiseEvent
End Event
Protected Overridable Sub OnValChanged(ByVal e As ValueChangedEventArgs)
RaiseEvent ValChanged(Me, e)
End Sub
Private Event INotifyPropertyChanged_PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Sub NotifyPropertyChanged(ByVal info As String)
Select Case info
Case "Value"
RaiseEvent ValueChanged(Me, New ValueChangedEventArgs(Value))
TB.Tag = Value
TB.Text = Value.ToString("N0")
End Select
End Sub
#End Region
Public Sub New()
InitializeComponent()
Me.DataContext = Me
End Sub
#Region "ValueProperty"
Public Shared ValueProperty As DependencyProperty = DependencyProperty.RegisterAttached("Value", GetType(BigInteger), GetType(BigIntegerUpDown))
Public Property Value() As BigInteger
Get
Return GetValue(ValueProperty)
End Get
Set(ByVal value As BigInteger)
If value < MinValue Then
value = MinValue
End If
If value > MaxValue Then
value = MaxValue
End If
SetValue(ValueProperty, value)
NotifyPropertyChanged("Value")
End Set
End Property
#End Region
#Region "StepProperty"
Public Shared SmallStepProperty As DependencyProperty = DependencyProperty.RegisterAttached("SmallStep", GetType(BigInteger), GetType(BigIntegerUpDown), New PropertyMetadata(BigInteger.One))
Public Property SmallStep() As BigInteger
Get
Return GetValue(SmallStepProperty) 'Dec(GetValue(StepProperty))
End Get
Set(ByVal value As BigInteger)
SetValue(SmallStepProperty, value)
End Set
End Property
Public Shared BigStepProperty As DependencyProperty = DependencyProperty.RegisterAttached("BigStep", GetType(BigInteger), GetType(BigIntegerUpDown), New PropertyMetadata(BigInteger.Parse("100")))
Public Property BigStep() As BigInteger
Get
Return GetValue(BigStepProperty) 'Dec(GetValue(BigStepProperty))
End Get
Set(ByVal value As BigInteger)
SetValue(BigStepProperty, value)
End Set
End Property
#End Region
#Region "MinValueProperty"
Public Shared MinValueProperty As DependencyProperty = DependencyProperty.RegisterAttached("MinValue", GetType(BigInteger), GetType(BigIntegerUpDown), New PropertyMetadata(BigInteger.Zero))
Public Property MinValue() As BigInteger
Get
Return GetValue(MinValueProperty) 'CDec(GetValue(MinValueProperty))
End Get
Set(ByVal value As BigInteger)
If value > MaxValue Then
MaxValue = value
End If
SetValue(MinValueProperty, value)
End Set
End Property
#End Region
#Region "MaxValueProperty"
Public Shared MaxValueProperty As DependencyProperty = DependencyProperty.RegisterAttached("MaxValue", GetType(BigInteger), GetType(BigIntegerUpDown), New PropertyMetadata(BigInteger.Parse("1000000000000000000000000000000")))
Public Property MaxValue() As BigInteger
Get
Return GetValue(MaxValueProperty) 'CDec(GetValue(MaxValueProperty))
End Get
Set(ByVal value As BigInteger)
If value < MinValue Then
value = MinValue
End If
SetValue(MaxValueProperty, value)
End Set
End Property
#End Region
#Region "Up/Down"
Private Sub cmdUp_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
If Keyboard.Modifiers = ModifierKeys.Control Then
Value += BigStep
Else
Value += SmallStep
End If
NotifyPropertyChanged("Value")
End Sub
Private Sub cmdDown_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
If Keyboard.Modifiers = ModifierKeys.Control Then
Value -= BigStep
Else
Value -= SmallStep
End If
NotifyPropertyChanged("Value")
End Sub
Private Sub TB_MouseWheel(sender As Object, e As MouseWheelEventArgs)
If e.Delta > 0 Then
If Keyboard.Modifiers = ModifierKeys.Control Then
Value += BigStep
Else
Value += SmallStep
End If
NotifyPropertyChanged("Value")
ElseIf e.Delta < 0 Then
If Keyboard.Modifiers = ModifierKeys.Control Then
Value -= BigStep
Else
Value -= SmallStep
End If
NotifyPropertyChanged("Value")
End If
End Sub
#End Region
Private Sub TB_TextChanged(sender As Object, e As TextChangedEventArgs)
NotifyPropertyChanged("Value")
End Sub
End Class
Public Class ValueChangedEventArgs
Inherits EventArgs
Public Property NewValue As BigInteger
Public Sub New(ByVal value As BigInteger)
NewValue = value
End Sub
Public Overrides Function ToString() As String
Return NewValue.ToString("N0")
End Function
End Class
Public Class BigIntToStringConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
If TypeOf value Is BigInteger Then
Return Strings.FormatNumber(value.ToString(), 0, TriState.UseDefault, TriState.False, TriState.True)
End If
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
Return BigInteger.Parse(value, NumberStyles.AllowThousands Or NumberStyles.Integer Or NumberStyles.AllowLeadingSign)
End Function
End Class