diff --git a/Elwig/Controls/UnitTextBox.xaml b/Elwig/Controls/UnitTextBox.xaml
index 7691c1d..4fa1e8f 100644
--- a/Elwig/Controls/UnitTextBox.xaml
+++ b/Elwig/Controls/UnitTextBox.xaml
@@ -4,7 +4,7 @@
+ Text="{Binding Path=Text}" TextChanged="TextBox_TextChanged"/>
diff --git a/Elwig/Controls/UnitTextBox.xaml.cs b/Elwig/Controls/UnitTextBox.xaml.cs
index a3093e6..675fd8d 100644
--- a/Elwig/Controls/UnitTextBox.xaml.cs
+++ b/Elwig/Controls/UnitTextBox.xaml.cs
@@ -1,6 +1,5 @@
using System.Windows;
using System.Windows.Controls;
-using System.Windows.Data;
namespace Elwig.Controls {
public partial class UnitTextBox : UserControl {
@@ -10,22 +9,29 @@ namespace Elwig.Controls {
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(UnitTextBox));
public string Text {
get => (string)GetValue(TextProperty);
- set => SetValue(TextProperty, value);
+ set => SetValue(TextProperty, value ?? "");
}
public static readonly DependencyProperty UnitProperty = DependencyProperty.Register("Unit", typeof(string), typeof(UnitTextBox));
public string Unit {
get => (string)GetValue(UnitProperty);
- set => SetValue(UnitProperty, value);
+ set => SetValue(UnitProperty, value ?? "");
}
public UnitTextBox() {
+ Text = "";
+ Unit = "";
InitializeComponent();
DataContext = this;
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs evt) {
- if (TextChanged != null) TextChanged(sender, evt);
+ Text = TextBox.Text;
+ TextChanged?.Invoke(sender, evt);
+ }
+
+ public new void Focus() {
+ TextBox.Focus();
}
}
}
diff --git a/Elwig/Helpers/Validator.cs b/Elwig/Helpers/Validator.cs
index 064572d..2874f78 100644
--- a/Elwig/Helpers/Validator.cs
+++ b/Elwig/Helpers/Validator.cs
@@ -63,13 +63,15 @@ namespace Elwig.Helpers {
return CheckDecimal(input, required, -1, -1);
}
- public static ValidationResult CheckDecimal(TextBox input, bool required, int maxLen, int maxDecimal) {
+ public static ValidationResult CheckDecimal(TextBox input, bool required, int maxLen, int maxDecimal, bool allowMinus = false) {
string text = "";
int pos = input.CaretIndex;
int v1 = 0, v2 = -1;
for (int i = 0; i < input.Text.Length; i++) {
char ch = input.Text[i];
- if (char.IsAsciiDigit(ch)) {
+ if (ch == '-' && i == 0 && allowMinus) {
+ text += ch;
+ } else if (char.IsAsciiDigit(ch)) {
if (v2 == -1 && (maxLen == -1 || v1 < maxLen)) {
text += ch; v1++;
} else if (v2 != -1 && (maxDecimal == -1 || v2 < maxDecimal)) {
diff --git a/Elwig/Windows/AdministrationWindow.cs b/Elwig/Windows/AdministrationWindow.cs
index 7a6eb05..87cf652 100644
--- a/Elwig/Windows/AdministrationWindow.cs
+++ b/Elwig/Windows/AdministrationWindow.cs
@@ -63,10 +63,12 @@ namespace Elwig.Windows {
OriginalValues = new();
DefaultValues = new();
Closing += OnClosing;
+ Loaded -= base.OnLoaded;
Loaded += OnLoaded;
+ Loaded += base.OnLoaded;
}
- private void OnLoaded(object sender, RoutedEventArgs evt) {
+ private new void OnLoaded(object sender, RoutedEventArgs evt) {
TextBoxInputs = ControlUtils.FindAllChildren(this, ExemptInputs).ToArray();
ComboBoxInputs = ControlUtils.FindAllChildren(this, ExemptInputs).ToArray();
CheckBoxInputs = ControlUtils.FindAllChildren(this, ExemptInputs).ToArray();
diff --git a/Elwig/Windows/BaseDataWindow.xaml b/Elwig/Windows/BaseDataWindow.xaml
index bbafb13..72f33f7 100644
--- a/Elwig/Windows/BaseDataWindow.xaml
+++ b/Elwig/Windows/BaseDataWindow.xaml
@@ -1,11 +1,13 @@
-