Fixed 4 digit time entry
This commit is contained in:
parent
ac21a2fa45
commit
6f1346c430
@ -9,12 +9,15 @@ namespace BreCalClient
|
|||||||
protected override void OnPreviewTextInput(TextCompositionEventArgs e)
|
protected override void OnPreviewTextInput(TextCompositionEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnPreviewTextInput(e);
|
base.OnPreviewTextInput(e);
|
||||||
|
|
||||||
// Die vom Agenten "vorgeschlagene" Zeit könnte auch der Watermark sein?
|
|
||||||
|
|
||||||
string text = this.Text + e.Text;
|
|
||||||
if (this.Template.FindName("PART_TextBox", this) is not WatermarkTextBox tb) return;
|
if (this.Template.FindName("PART_TextBox", this) is not WatermarkTextBox tb) return;
|
||||||
|
|
||||||
|
// strip input after caret
|
||||||
|
string subText = (tb.CaretIndex > 0) ? this.Text[..tb.CaretIndex] : tb.Text; // Range operator instead of Substring(0, tb.CaretIndex)
|
||||||
|
string text = subText + e.Text;
|
||||||
|
|
||||||
|
// System.Diagnostics.Debug.WriteLine("C:" + this.Text + " E: " + e.Text + " Caret: " + tb.CaretIndex + " Subt: " + subText);
|
||||||
|
|
||||||
|
// 10 char eingabe "am Stück"
|
||||||
if (Regex.IsMatch(text, @"^\d{10}"))
|
if (Regex.IsMatch(text, @"^\d{10}"))
|
||||||
{
|
{
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
@ -23,32 +26,15 @@ namespace BreCalClient
|
|||||||
tb.SelectedText = "";
|
tb.SelectedText = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// nur die Zeit wird markiert und mit 4 Zahlen befüllt, diese Regel setzt den Doppelpunkt
|
||||||
if (Regex.IsMatch(text, @"^\d{3}"))
|
else if (Regex.IsMatch(text, @"^(\d{2}\.\d{2}\. \d{4} \d{3})"))
|
||||||
{
|
{
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
tb.Text = Regex.Replace(text, @"(\d{2})(\d)", "$1.$2");
|
tb.Text = Regex.Replace(text, @"(\d{2}\.\d{2}\. \d{4} \d{2})(\d)(.*)", "$1:$2");
|
||||||
|
// System.Diagnostics.Trace.WriteLine("Replaced: " + tb.Text);
|
||||||
tb.CaretIndex = tb.Text.Length;
|
tb.CaretIndex = tb.Text.Length;
|
||||||
|
tb.Select(tb.Text.Length, 0);
|
||||||
}
|
}
|
||||||
else if (Regex.IsMatch(text, @"^(\d{2}\.\d{3})"))
|
|
||||||
{
|
|
||||||
e.Handled = true;
|
|
||||||
tb.Text = Regex.Replace(text, @"^(\d{2}\.\d{2})(\d)", "$1.$2");
|
|
||||||
tb.CaretIndex = tb.Text.Length;
|
|
||||||
}
|
|
||||||
else if (Regex.IsMatch(text, @"^(\d{2}\.\d{2}\.\d{2} \d{3})"))
|
|
||||||
{
|
|
||||||
e.Handled = true;
|
|
||||||
tb.Text = Regex.Replace(text, @"(\d{2}\.\d{2}\.\d{2} \d{2})(\d)", "$1:$2");
|
|
||||||
tb.CaretIndex = tb.Text.Length;
|
|
||||||
}
|
|
||||||
else if (Regex.IsMatch(text, @"^(\d{2}\.\d{2}\.\d{4} \d{3})"))
|
|
||||||
{
|
|
||||||
e.Handled = true;
|
|
||||||
tb.Text = Regex.Replace(text, @"(\d{2}\.\d{2}\.\d{4} \d{2})(\d)", "$1:$2");
|
|
||||||
tb.CaretIndex = tb.Text.Length;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user