From 8180367da0e1344314a579279d839914e6d5c7b9 Mon Sep 17 00:00:00 2001 From: nrpog Date: Thu, 18 Feb 2016 14:38:39 +0000 Subject: [PATCH 1/6] Added ContentStringFormat TemplateBinding to ToolTip --- MahApps.Metro/Styles/Controls.Tooltip.xaml | 1 + 1 file changed, 1 insertion(+) diff --git a/MahApps.Metro/Styles/Controls.Tooltip.xaml b/MahApps.Metro/Styles/Controls.Tooltip.xaml index 005ffcec0d..cb46dab2f8 100644 --- a/MahApps.Metro/Styles/Controls.Tooltip.xaml +++ b/MahApps.Metro/Styles/Controls.Tooltip.xaml @@ -59,6 +59,7 @@ TextElement.FontSize="{DynamicResource ContentFontSize}" Cursor="{TemplateBinding Cursor}" ContentTemplate="{TemplateBinding ContentTemplate}" + ContentStringFormat="{TemplateBinding ContentStringFormat}" Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}" /> From 0708f0edf51fe7276801dc2a12d0bb298efdbbae Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Fri, 19 Feb 2016 23:29:12 +0100 Subject: [PATCH 2/6] Revert "Added ContentStringFormat TemplateBinding to ToolTip" --- MahApps.Metro/Styles/Controls.Tooltip.xaml | 1 - 1 file changed, 1 deletion(-) diff --git a/MahApps.Metro/Styles/Controls.Tooltip.xaml b/MahApps.Metro/Styles/Controls.Tooltip.xaml index cb46dab2f8..005ffcec0d 100644 --- a/MahApps.Metro/Styles/Controls.Tooltip.xaml +++ b/MahApps.Metro/Styles/Controls.Tooltip.xaml @@ -59,7 +59,6 @@ TextElement.FontSize="{DynamicResource ContentFontSize}" Cursor="{TemplateBinding Cursor}" ContentTemplate="{TemplateBinding ContentTemplate}" - ContentStringFormat="{TemplateBinding ContentStringFormat}" Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}" /> From f3544a8a680e92c43ffa94a49853e0dc2e2d8e47 Mon Sep 17 00:00:00 2001 From: Michel Feinstein Date: Mon, 7 Mar 2016 20:18:41 -0300 Subject: [PATCH 3/6] Fixes the HasDecimals property, broken befor on commit #bd6aa38e. --- MahApps.Metro/Controls/NumericUpDown.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MahApps.Metro/Controls/NumericUpDown.cs b/MahApps.Metro/Controls/NumericUpDown.cs index df15484ff0..b0d7b0e493 100644 --- a/MahApps.Metro/Controls/NumericUpDown.cs +++ b/MahApps.Metro/Controls/NumericUpDown.cs @@ -1063,7 +1063,7 @@ private void OnTextBoxKeyDown(object sender, KeyEventArgs e) { _manualChange = true; - if (e.Key == Key.Decimal || e.Key == Key.OemPeriod) + if (HasDecimals == true && (e.Key == Key.Decimal || e.Key == Key.OemPeriod)) { TextBox textBox = sender as TextBox; From 78a80890a1ff75931ef167ffb03443d584d2a32b Mon Sep 17 00:00:00 2001 From: Jan Karger Date: Tue, 8 Mar 2016 09:31:08 +0100 Subject: [PATCH 4/6] Revert "Fixes the HasDecimals property, broken before on commit bd6aa38e." --- MahApps.Metro/Controls/NumericUpDown.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MahApps.Metro/Controls/NumericUpDown.cs b/MahApps.Metro/Controls/NumericUpDown.cs index b0d7b0e493..df15484ff0 100644 --- a/MahApps.Metro/Controls/NumericUpDown.cs +++ b/MahApps.Metro/Controls/NumericUpDown.cs @@ -1063,7 +1063,7 @@ private void OnTextBoxKeyDown(object sender, KeyEventArgs e) { _manualChange = true; - if (HasDecimals == true && (e.Key == Key.Decimal || e.Key == Key.OemPeriod)) + if (e.Key == Key.Decimal || e.Key == Key.OemPeriod) { TextBox textBox = sender as TextBox; From 7f681f68ddd43742b3b67776c759837ed9bf7207 Mon Sep 17 00:00:00 2001 From: Michel Feinstein Date: Wed, 9 Mar 2016 23:53:28 -0300 Subject: [PATCH 5/6] Added the habilitiy to block the use of the scientific notation 'e', using the property HasScientificNotation. Updated the example as well. --- MahApps.Metro/Controls/NumericUpDown.cs | 23 +++++++++++++++++-- .../MetroDemo/ExampleViews/TextExamples.xaml | 11 +++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/MahApps.Metro/Controls/NumericUpDown.cs b/MahApps.Metro/Controls/NumericUpDown.cs index fa488211f2..ade0f43f77 100644 --- a/MahApps.Metro/Controls/NumericUpDown.cs +++ b/MahApps.Metro/Controls/NumericUpDown.cs @@ -159,6 +159,12 @@ private static void InterceptManualEnterChangedCallback(DependencyObject depende typeof(NumericUpDown), new FrameworkPropertyMetadata(true, OnHasDecimalsChanged)); + public static readonly DependencyProperty HasScientificNotationProperty = DependencyProperty.Register( + "HasScientificNotation", + typeof(bool), + typeof(NumericUpDown), + new PropertyMetadata(true)); + private static readonly Regex RegexStringFormatHexadecimal = new Regex(@"^(?.*{\d:X\d+}.*)?(?X\d+)?$", RegexOptions.Compiled); private const double DefaultInterval = 1d; @@ -463,6 +469,18 @@ public bool HasDecimals set { SetValue(HasDecimalsProperty, value); } } + /// + /// Indicates if the NumericUpDown should show the decimal separator or not. + /// + [Bindable(true)] + [Category("Common")] + [DefaultValue(true)] + public bool HasScientificNotation + { + get { return (bool)GetValue(HasScientificNotationProperty); } + set { SetValue(HasScientificNotationProperty, value); } + } + /// /// Called when this element or any below gets focus. /// @@ -704,13 +722,14 @@ protected void OnPreviewTextInput(object sender, TextCompositionEventArgs e) else if (textBox.SelectionStart > 0) { string elementBeforeCaret = textBox.Text.ElementAt(textBox.SelectionStart - 1).ToString(equivalentCulture); - if (elementBeforeCaret.Equals(ScientificNotationChar, StrComp)) + if (elementBeforeCaret.Equals(ScientificNotationChar, StrComp) && HasScientificNotation) { e.Handled = false; } } } - else if (text.Equals(ScientificNotationChar, StrComp) && + else if (HasScientificNotation && + text.Equals(ScientificNotationChar, StrComp) && textBox.SelectionStart > 0 && !textBox.Text.Any(i => i.ToString(equivalentCulture).Equals(ScientificNotationChar, StrComp))) { diff --git a/samples/MetroDemo/ExampleViews/TextExamples.xaml b/samples/MetroDemo/ExampleViews/TextExamples.xaml index c125f0e75b..7e791c4420 100644 --- a/samples/MetroDemo/ExampleViews/TextExamples.xaml +++ b/samples/MetroDemo/ExampleViews/TextExamples.xaml @@ -245,11 +245,16 @@ Margin="1" Content="HasDecimals" IsChecked="True" /> +