Merge pull request #514 from GF-Huang/master

Add "StringFormat" property for NumericUpDown control.
This commit is contained in:
NaBian authored and GitHub committed 2020-11-25 21:48:59 +08:00
commit 0ef2005285
2 files changed
+21 -4

No files matched your search

@@ -15,7 +15,7 @@
<hc:NumericUpDown hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr1}}" Margin="0,32,0,0" Style="{StaticResource NumericUpDownExtend}"/>
<hc:NumericUpDown hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr1}}" Margin="0,32,0,0" hc:InfoElement.Necessary="True" Style="{StaticResource NumericUpDownExtend}"/>
<hc:NumericUpDown Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Style="{StaticResource NumericUpDownExtend}" Margin="0,32,0,0"/>
<hc:NumericUpDown Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Style="{StaticResource NumericUpDownExtend}" hc:InfoElement.Necessary="True" Margin="0,32,0,0"/>
<hc:NumericUpDown ValueFormat="N2" Maximum="100000" Value="10000" Width="380" hc:InfoElement.TitleWidth="140" hc:InfoElement.Placeholder="{ex:Lang Key={x:Static langs:LangKeys.PlsEnterContent}}" hc:InfoElement.TitlePlacement="Left" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr3}}" Style="{StaticResource NumericUpDownExtend}" hc:InfoElement.Necessary="True" Margin="0,32,0,0"/>
</StackPanel>
<StackPanel Margin="32,0,0,0">
<hc:NumericUpDown Name="NumericUpDownCustomVerify" ShowClearButton="True" Style="{StaticResource NumericUpDownPlus}"/>
@@ -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<double> e) => RaiseEvent(e);
@@ -318,6 +320,21 @@ namespace HandyControl.Controls
set => SetValue(DecimalPlacesProperty, value);
}
/// <summary>
/// 指示要显示的数字的格式
/// </summary>
public static readonly DependencyProperty ValueFormatProperty = DependencyProperty.Register(
"ValueFormat", typeof(string), typeof(NumericUpDown), new PropertyMetadata(default(string)));
/// <summary>
/// 指示要显示的数字的格式,这将会覆盖 <see cref="DecimalPlaces"/> 属性
/// </summary>
public string ValueFormat
{
get => (string) GetValue(ValueFormatProperty);
set => SetValue(ValueFormatProperty, value);
}
/// <summary>
/// 是否显示上下调值按钮
/// </summary>