diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/NumericUpDownDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/NumericUpDownDemoCtl.xaml index ccebf3aa..e09deb85 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/NumericUpDownDemoCtl.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/NumericUpDownDemoCtl.xaml @@ -15,7 +15,7 @@ - + diff --git a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs index 28dbba39..cc544656 100644 --- a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs +++ b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs @@ -153,9 +153,11 @@ namespace HandyControl.Controls } } - private string CurrentText => DecimalPlaces.HasValue - ? Value.ToString($"#0.{new string('0', DecimalPlaces.Value)}") - : Value.ToString("#0"); + private string CurrentText => string.IsNullOrWhiteSpace(ValueFormat) + ? DecimalPlaces.HasValue + ? Value.ToString($"#0.{new string('0', DecimalPlaces.Value)}") + : Value.ToString("#0") + : Value.ToString(ValueFormat); protected virtual void OnValueChanged(FunctionEventArgs e) => RaiseEvent(e); @@ -318,6 +320,21 @@ namespace HandyControl.Controls set => SetValue(DecimalPlacesProperty, value); } + /// + /// 指示要显示的数字的格式 + /// + public static readonly DependencyProperty ValueFormatProperty = DependencyProperty.Register( + "ValueFormat", typeof(string), typeof(NumericUpDown), new PropertyMetadata(default(string))); + + /// + /// 指示要显示的数字的格式,这将会覆盖 属性 + /// + public string ValueFormat + { + get => (string) GetValue(ValueFormatProperty); + set => SetValue(ValueFormatProperty, value); + } + /// /// 是否显示上下调值按钮 ///