-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrencyBox.cs
32 lines (29 loc) · 942 Bytes
/
CurrencyBox.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
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace Budget
{
class CurrencyBox : TextBox
{
public string BindingPath
{
get { return GetBindingExpression(CurrencyBox.TextProperty).ParentBinding.Path.Path; }
set
{
var textBinding = new Binding(value) { Converter = new CurrencyConverter() };
textBinding.ValidationRules.Add(new CurrencyValidator());
SetBinding(CurrencyBox.TextProperty, textBinding);
SetBinding(CurrencyBox.ForegroundProperty, new Binding(value) { Converter = new CurrencyColorer() });
}
}
public CurrencyBox()
{
TextAlignment = TextAlignment.Right;
GotFocus += gotFocus;
}
private void gotFocus(object sender, RoutedEventArgs e)
{
SelectAll();
}
}
}