Skip to content

Commit 619a370

Browse files
authored
Fixing BrushOpacityConverter to always parse consistently (#2162)
1 parent a38e0be commit 619a370

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Globalization;
2+
using System.Windows.Media;
3+
using MaterialDesignThemes.Wpf.Converters;
4+
using Xunit;
5+
6+
namespace MaterialDesignThemes.Wpf.Tests.Converters
7+
{
8+
public class BrushOpacityConverterTests
9+
{
10+
[Theory]
11+
[InlineData("0.16", 0.16)]
12+
public void AllCultureParseParameterCorrectly(object parameter, double expectedOpacity)
13+
{
14+
var converter = new BrushOpacityConverter();
15+
foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
16+
{
17+
var inputBrush = new SolidColorBrush { Color = Colors.Red };
18+
var brush = (SolidColorBrush)converter.Convert(inputBrush, typeof(Brush), parameter, culture);
19+
Assert.Equal(expectedOpacity, brush.Opacity);
20+
}
21+
}
22+
}
23+
}

MaterialDesignThemes.Wpf/Converters/BrushOpacityConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1111
{
1212
if (value is SolidColorBrush brush)
1313
{
14-
var opacity = System.Convert.ToDouble(parameter, culture);
14+
var opacity = System.Convert.ToDouble(parameter, CultureInfo.InvariantCulture);
1515
return new SolidColorBrush(brush.Color)
1616
{
1717
Opacity = opacity

0 commit comments

Comments
 (0)