WPF Binding Converters equivalent in Telerik Blazor?
1 Answer 17 Views
Adrian
Top achievements
Rank 1
Iron
Veteran
Iron
Adrian asked on 17 Jun 2021, 06:03 PM | edited on 18 Jun 2021, 08:58 AM

I have a .NET Framework WPF Silverlight app which I am converting across to .NET Core Blazor WebAssembly.  The existing app heavily uses binding converters (that implement System.Windows.Data.IValueConverter) throughout the UI codebase.

The <telerik:Rad* controls make use of these converters.  Is there an equivalent to this for the Telerik Blazor controls?

N.B. Some of the converters are used in two-way binding.

Some examples of these existing converters:

Imports System.Windows.Data

Public Class DecimalZeroBlankConverter
    Implements IValueConverter

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
        If value Is Nothing Then
            Return Nothing
        End If

        If value = 0 Then
            Return Nothing
        End If

        Dim dec As Decimal = value

        Return dec.ToString("###,###,##0.00")
    End Function

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
        Throw New NotImplementedException
    End Function
End Class

Imports System.Windows.Data

Public Class PercentageConverter
    Implements IValueConverter

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
        If value Is Nothing Then
            Return 0
        End If

        Return value * 100
    End Function

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
        If value Is Nothing Then
            Return 0
        End If

        If String.IsNullOrEmpty(value) Then
            Return 0
        End If

        Return value / 100
    End Function
End Class

Imports System.Windows.Data

Public Class YesNoVisibilityConverter
    Implements IValueConverter

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
        If value Is Nothing Then
            Return Visibility.Collapsed
        End If

        If value = "Y" Then
            Return Visibility.Visible
        Else
            Return Visibility.Collapsed
        End If
    End Function

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
        Throw New NotImplementedException
    End Function
End Class

Imports System.Windows.Data

Public Class BooleanFontWeightConverter
    Implements IValueConverter

    Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
        If value Then
            Return FontWeights.Bold
        Else
            Return FontWeights.Normal
        End If
    End Function

    Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
        Throw New NotImplementedException
    End Function
End Class

1 Answer, 1 is accepted

Sort by
0
Svetoslav Dimitrov
Telerik team
answered on 22 Jun 2021, 12:18 PM

Hello Adrian,

It seems that Value converters are supported for Blazor. You can find more information on the topic from the Blazor (client): Support value converters or similar for binding GitHub issue in Microsoft's ASP Net Core repository.

Let us know if you need any further assistance!

Regards,
Svetoslav Dimitrov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Asked by
Adrian
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Svetoslav Dimitrov
Telerik team
Share this question
or