Add "StringFormat" property for NumericUpDown control.

This commit is contained in:
GF-Huang committed 2020-11-23 21:35:14 +08:00
1 parent e99f1fe429
commit f28fa3ad84
2 files changed
+36 -3

No files matched your search

@@ -153,9 +153,21 @@ namespace HandyControl.Controls
}
}
private string CurrentText => DecimalPlaces.HasValue
? Value.ToString($"#0.{new string('0', DecimalPlaces.Value)}")
: Value.ToString("#0");
private string CurrentText
{
get
{
if (string.IsNullOrWhiteSpace(StringFormat))
{
return DecimalPlaces.HasValue ? Value.ToString($"#0.{new string('0', DecimalPlaces.Value)}") :
Value.ToString("#0");
}
else
{
return Value.ToString(StringFormat);
}
}
}
protected virtual void OnValueChanged(FunctionEventArgs<double> e) => RaiseEvent(e);
@@ -318,6 +330,21 @@ namespace HandyControl.Controls
set => SetValue(DecimalPlacesProperty, value);
}
/// <summary>
/// 指示要显示的数字的格式
/// </summary>
public static readonly DependencyProperty StringFormatProperty =
DependencyProperty.Register("StringFormat", typeof(string), typeof(NumericUpDown), new PropertyMetadata(default(string)));
/// <summary>
/// 指示要显示的数字的格式,这将会覆盖 <see cref="DecimalPlaces"/> 属性
/// </summary>
public string StringFormat
{
get { return (string)GetValue(StringFormatProperty); }
set { SetValue(StringFormatProperty, value); }
}
/// <summary>
/// 是否显示上下调值按钮
/// </summary>