Example #1
0
        private void InternalSetText(double?newValue)
        {
            if (!newValue.HasValue)
            {
                _valueTextBox.Text = null;
                return;
            }

            CultureInfo culture = SpecificCultureInfo;

            if (string.IsNullOrEmpty(StringFormat))
            {
                _valueTextBox.Text = newValue.Value.ToString(culture);
            }
            else if (!StringFormat.Contains("{"))
            {
                // then we may have a StringFormat of e.g. "N0"
                _valueTextBox.Text = newValue.Value.ToString(StringFormat, culture);
            }
            else
            {
                _valueTextBox.Text = string.Format(culture, StringFormat, newValue.Value);
            }

            if ((bool)GetValue(TextboxHelper.IsMonitoringProperty))
            {
                SetValue(TextboxHelper.TextLengthProperty, _valueTextBox.Text.Length);
            }
        }
Example #2
0
        private void FormatValue(double?newValue, CultureInfo culture)
        {
            var match = RegexStringFormatHexadecimal.Match(StringFormat);

            if (match.Success)
            {
                if (match.Groups["simpleHEX"].Success)
                {
                    // HEX DOES SUPPORT INT ONLY.
                    _valueTextBox.Text = ((int)newValue.Value).ToString(match.Groups["simpleHEX"].Value, culture);
                }
                else if (match.Groups["complexHEX"].Success)
                {
                    _valueTextBox.Text = string.Format(culture, match.Groups["complexHEX"].Value, (int)newValue.Value);
                }
            }
            else
            {
                if (!StringFormat.Contains("{"))
                {
                    // then we may have a StringFormat of e.g. "N0"
                    _valueTextBox.Text = newValue.Value.ToString(StringFormat, culture);
                }
                else
                {
                    _valueTextBox.Text = string.Format(culture, StringFormat, newValue.Value);
                }
            }
        }