Skip to content

Commit

Permalink
SpinnerTextToValueConverter now also gets the format string when conv…
Browse files Browse the repository at this point in the history
…erting from string to double. This enables full feature requested in #205
  • Loading branch information
batzen committed Dec 17, 2015
1 parent 556c9d5 commit 5c5323d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Fluent.Ribbon/Controls/Spinner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,8 @@ private void OnTextBoxPreviewKeyDown(object sender, KeyEventArgs e)

private void TextBoxTextToValue()
{
var newValue = (double)this.TextToValueConverter.Convert(this.textBox.Text, typeof(double), this.Value, CultureInfo.CurrentCulture);
var converterParam = new Tuple<string, double>(this.Format, this.Value);
var newValue = (double)this.TextToValueConverter.Convert(this.textBox.Text, typeof(double), converterParam, CultureInfo.CurrentCulture);

this.Value = GetLimitedValue(this, newValue);

Expand Down
8 changes: 6 additions & 2 deletions Fluent.Ribbon/Converters/SpinnerTextToValueConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ public class SpinnerTextToValueConverter : IValueConverter
{
public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return this.TextToDouble((string)value, (double)parameter, culture);
var converterParam = (Tuple<string, double>)parameter;
var format = converterParam.Item1;
var previousValue = converterParam.Item2;

return this.TextToDouble((string)value, format, previousValue, culture);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return this.DoubleToText((double)value, (string)parameter, culture);
}

public virtual double TextToDouble(string text, double previousValue, CultureInfo culture)
public virtual double TextToDouble(string text, string format, double previousValue, CultureInfo culture)
{
// Remove all except digits, signs and commas
var stringBuilder = new StringBuilder();
Expand Down

0 comments on commit 5c5323d

Please sign in to comment.