3

Is there a built-in class to do the conversion from a string to those common types?

For example, to convert "1,2,3,4" to a Thickness or "#00AABBCC" to a Brush.

SuperJMN
  • 13,110
  • 16
  • 86
  • 185

2 Answers2

2

No. There are no built-in from-string-converters for Thickness or Brush in UWP.

But here's how you can create a StringToSolidColorBrushConverter.

And here's the source code of .NET's System.Windows.ThicknessConverter. Though, it works only in .NET Framework, you can take the converter algorithm from the FromString(..) method.

Community
  • 1
  • 1
Artemious
  • 1,980
  • 1
  • 20
  • 31
1

Old post, but anyone looking for this, you can use

(Thickness)XamlBindingHelper.ConvertValue(typeof(Thickness), value)

Not just for thickness, but for lots of types. This is also working in WinUI3

XamlBindingHelper documentation

benderto
  • 896
  • 11
  • 39