Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix slider localization bug #13348

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Libraries/CoreNodeModelsWpf/SliderViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;

using System;
using System.Globalization;
using CoreNodeModels.Input;

using Dynamo.Core;
Expand Down Expand Up @@ -63,7 +63,16 @@ public T Value
if (value.CompareTo(model.Min) == -1)
model.Min = value;

model.UpdateValue(new Dynamo.Graph.UpdateValueParams(nameof(Value), value.ToString()));
if(value is IFormattable formattableval)
{
var invariantString = formattableval.ToString(null,CultureInfo.InvariantCulture);
model.UpdateValue(new Dynamo.Graph.UpdateValueParams(nameof(Value), invariantString));
}
else
{
model.UpdateValue(new Dynamo.Graph.UpdateValueParams(nameof(Value), value.ToString()));
}

}
}

Expand Down Expand Up @@ -98,4 +107,4 @@ private void model_PropertyChanged(
}

}
}
}
43 changes: 42 additions & 1 deletion test/DynamoCoreWpfTests/SliderViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Windows.Controls;
using CoreNodeModels;
using CoreNodeModels.Input;
Expand Down Expand Up @@ -132,5 +134,44 @@ public void SliderViewModel_ValueTest()
Assert.AreEqual("-200", minTextBox.Text);
Assert.AreEqual("200", maxTextBox.Text);
}

/// <summary>
/// This test will validate that setting the string in a , dec seperator culture does not
/// modify the value.
/// </summary>
[Test]
public void SliderViewModel_ValueTest_Localized()
{
//change current thread culture to German.
var deCulture = CultureInfo.CreateSpecificCulture("de-DE");

var currentCulture = Thread.CurrentThread.CurrentCulture;
var currentUICulture = Thread.CurrentThread.CurrentUICulture;

Thread.CurrentThread.CurrentCulture = deCulture;
Thread.CurrentThread.CurrentUICulture = deCulture;

//create a slider
var slider = new CoreNodeModels.Input.DoubleSlider();
Model.CurrentWorkspace.AddAndRegisterNode(slider);

DispatcherUtil.DoEvents();

//get viewmodel.
var nodeViews = View.NodeViewsInFirstWorkspace();
var nodeView = nodeViews.OfNodeModelType<CoreNodeModels.Input.DoubleSlider>().FirstOrDefault();
var dynamoSliderControl = nodeView.grid.ChildrenOfType<DynamoSlider>().FirstOrDefault();
//Setting the Value property from the SliderViewModel
var sliderViewModel = dynamoSliderControl.DataContext as SliderViewModel<double>;
sliderViewModel.Value = 10.7;

DispatcherUtil.DoEvents();

Assert.AreEqual(10.7,slider.Value);
//reset culture
Thread.CurrentThread.CurrentCulture = currentCulture;
Thread.CurrentThread.CurrentUICulture = currentUICulture;

}
}
}