Search
IValueConverter Interface
Remarks See Also
 





Enables explicit conversion from one data type to another during data-binding.

Namespace: MindFusion.Scheduling.DataBinding
Assembly: MindFusion.Scheduling

 Syntax

C#  Copy Code

public interface IValueConverter

Visual Basic  Copy Code

Public Interface IValueConverter

 Remarks

When you need to perform explicit type conversion during databinding, you need to implement this interface and supply an instance of your class to the LoadFromDataSource method of the Calendar class. During loading the Supports method of the IValueConverter interface is invoked every time a value from the data source is transferred to the respective destination property to check whether the value should be converted. If Supports returns true, then Convert is invoked in order to perform the actual conversion.

 Example

The following example demonstrates a sample implementation of the IValueConverter interface which converts all byte values to boolean:

C#  Copy Code

public class ByteToBoolConverter : IValueConverter
{
    public object Convert(object value, object destination, string destinationMember, Type destinationType)
    {
        if (value is byte && destinationType == typeof(bool))
            return (byte)value != 0;

        return value;
    }

    public bool Supports(object value, object destination, string destinationMember, Type destinationType)
    {
        return value is byte && destinationType == typeof(bool);
    }
}

Visual Basic  Copy Code

Public Class ByteToBoolConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal destination As Object, _
        ByVal destinationMember As String, ByVal destinationType As Type) As Object Implements IValueConverter.Convert

        If TypeOf value Is Byte And destinationType Is GetType(Boolean) Then
            Return CByte(value) <> 0
        End If

        Return value

    End Function

    Public Function Supports(ByVal value As Object, ByVal destination As Object, _
        ByVal destinationMember As String, ByVal destinationType As Type) As Boolean Implements IValueConverter.Supports

        Return TypeOf value Is Byte And destinationType Is GetType(Boolean)

    End Function

End Class

 See Also