Namespace Controls
Public Class StringTitleConverter
Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
If targetType = GetType(String) AndAlso TypeOf value Is TextBlock Then
Dim title As String = String.Empty
With DirectCast(value, TextBlock)
Select Case .TextAlignment
Case TextAlignment.Left : title = "L,"
Case TextAlignment.Right : title = "R,"
Case TextAlignment.Center : title = "C,"
End Select
title += .Text
Return title
End With
End If
Return String.Empty
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
If targetType = GetType(FrameworkElement) AndAlso TypeOf value Is String Then
Dim align = TextAlignment.Left
Dim p = InStr(value, ",")
If p > 0 Then
Select Case LCase(value(0))
Case "l" : align = TextAlignment.Left
Case "r" : align = TextAlignment.Right
Case "c" : align = TextAlignment.Center
End Select
value = Trim(Mid(value, p + 1))
End If
Return mSupport.StringTitle(value, align)
End If
Return Nothing
End Function
End Class
End Namespace