Converters

Telerik controls provide a set of different built-in IValueConverters which can be used to perform conversion between different types.

To get access to these converters you can add reference to the Telerik.Windows.Controls.dll.

Example 1: Specifying converters in XAML

    <FrameworkElement> 
      <FrameworkElement.Resources> 
          <telerik:BooleanToOpacityConverter x:Key="BooleanToOpacityConverter"/> 
          <telerik:InvertedBooleanToOpacityConverter x:Key="InvertedBooleanToOpacityConverter"/> 
          <telerik:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> 
          <telerik:InvertedBooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter"/> 
          <telerik:EnumToVisibilityConverter x:Key="EnumToVisibilityConverter"/> 
          <telerik:ColorToBrushConverter x:Key="ColorToBrushConverter"/> 
          <telerik:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/> 
          <telerik:DateTimeTypeConverter x:Key="DateTimeTypeConverter"/> 
          <telerik:UppercaseConverter x:Key="UppercaseConverter"/> 
          <telerik:BinaryImageConverter x:Key="BinaryImageConverter"/> 
          <telerik:DoubleToThicknessConverter x:Key="DoubleToThicknessConverter"/> 
          <telerik:OpacityConverter x:Key="OpacityConverter"/> 
          <telerik:ThicknessToOrientedThicknessConverter x:Key="ThicknessToOrientedThicknessConverter"/> 
      </FrameworkElement.Resources> 
    </FrameworkElement> 

BooleanToOpacityConverter

This converter converts Boolean values to 1 or 0 opacity. If the Boolean value is false the converter will return 0 opacity.

InvertedBooleanToOpacityConverter

This converter converts Boolean values to 1 or 0 opacity. If the Boolean value is false the converter will return 1 opacity.

BooleanToVisibilityConverter

This converter converts Boolean values to Visibility enumeration values. If the Boolean value is false the Convert() method will return Visibility.Collapsed.

InvertedBooleanToVisibilityConverter

This converter converts Boolean values to Visibility enumeration values. If the Boolean value is true the Convert() method will return Visibility.Collapsed.

EnumToVisibilityConverter

Converts an Enum value to Visibility enumeration values. If the enum value is one of the values specified in the converter parameter, the Convert() method will return Visibility.Visible, otherwise it will return Visibility.Collapsed. Multiple enum values could be specified in the converter parameter, separated using , or ;.

Example 2: Setting the ViewModel

    public class MainViewModel 
    { 
        public Gender Gender { get; set; } 
    } 
 
    public enum Gender 
    { 
        Female, 
        Male 
    } 

Example 3: Setting the converter to the Visibility property

    <telerik:RadRadioButton Visibility="{Binding MyGender, Converter={StaticResource EnumToVisibilityConverter}, ConverterParameter=Male}"/> 

ColorToBrushConverter

This converter converts Color values to Brush values.

NullToVisibilityConverter

This converter converts Null or empty string values to Visibility enumeration values. If the input value is Null or empty string, the converter will return Visibility.Collapsed.

NumberToVisibilityConverter

This converter converts a number (double or integer) value to Visibility enumeration value. If the value is less than or equal to 0, returns Visibility.Collapsed, otherwise returns Visibility.Visible.

DateTimeTypeConverter

The converter converts string to a DateTime format value.

UppercaseConverter

This converter converts all lowcase to uppercase letters.

BinaryImageConverter

The converter converts byte array to System.Windows.Media.Imaging.BitmapImage object.

DoubleToThicknessConverter

The converter converts numeric value to Thickness based on the parameter.

Example 4: Setting the ViewModel

    public class MainViewModel 
    { 
        public double Thickness { get; set; } 
    } 

Example 5: Setting the converter to the BorderThickness property

     <Border Background="Green" BorderThickness="{Binding Thickness,Converter={StaticResource DoubleToThicknessConverter},ConverterParameter=LeftRight}" BorderBrush="Black"/> 

OpacityConverter

The converter applies opacity to a Color or Brush value based on the parameter.

Example 6: Setting the ViewModel

    public class MainViewModel 
    { 
        public MainViewModel() 
        { 
            Color = Brushes.Red; 
        } 
        public SolidColorBrush Color { get; set; } 
    } 

Example 7: Setting the converter to the Background property

    <Border Background="{Binding Color, Converter={StaticResource OpacityConverter},ConverterParameter=8}"  /> 

ThicknessToOrientedThicknessConverter

The converter applies Thickness to a property of type Thickness based on the parameter. The parameter expects string value which represents on which side you want to place border (LeftTopRightBottom). You can specify only two sides for example (LeftTop). The parameter is required.

Example 6: Setting the ViewModel

    public class MainWindow 
    { 
         public MainWindow() 
        { 
            InitializeComponent(); 
 
            this.DataContext = this; 
            Value = new Thickness(2, 3, 4, 5);               
        } 
        public Thickness Value { get; set; } 
    } 

Example 7: Setting the converter to the BorderThickness property

    <Border BorderThickness="{Binding Value,Converter={StaticResource ThicknessToOrientedThicknessConverter},ConverterParameter=LeftTop}" BorderBrush="Red" Width="200" Height="200" Background="Bisque"/> 

See Also

In this article
Not finding the help you need? Improve this article