WPF: How do I register additional implicit value converters? WPF: How do I register additional implicit value converters? wpf wpf

WPF: How do I register additional implicit value converters?


If you look at the source code you'll find this

public sealed class SolidColorBrush : Brush{  public Color Color  { ... }  ...}[TypeConverter(typeof (ColorConverter))]public struct Color : IFormattable, IEquatable<Color>{    ...}

The conversion is done by the ColorConverter.

And also

[TypeConverter(typeof (BrushConverter))]public abstract class Brush : Animatable, IFormattable, DUCE.IResource{ ... }public class TextBlock : ...{     public Brush Foreground   { ... }}

Where the conversion is done by BrushConverter.

There's no 'implicit' conversion that you can register. It's all done by applying TypeConverter attributes with the type of the appropriate value converter to relevant properties or classes.

In your example you need to use

<Window.Resources>    <SolidColorBrush x:Key="ForegroundFontColor" Color="Blue"/></Window.Resources><TextBlock Foreground={StaticResource ForegroundFontColor}>Hello</TextBlock>