Last active
May 26, 2017 21:47
-
-
Save feliperomero3/2e4b382672448ec36729b6ca5c582a3a to your computer and use it in GitHub Desktop.
Bool to Visibility converter for Windows Presentation Foundation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Converts true to Visibility.Visible and false to Visibility.Hidden (can be changed to Visibility Collapsed) | |
Public Class BoolVisibilityConverter | |
Implements IValueConverter | |
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert | |
If Not targetType = GetType(Visibility) Then | |
Throw New Exception("The target must be Visibility type") | |
End If | |
Dim valueAux As Nullable(Of Boolean) = CBool(value) | |
If parameter IsNot Nothing AndAlso parameter.ToString() = "PreviewFound" Then | |
Return If(valueAux.HasValue AndAlso valueAux.Value, Visibility.Hidden, Visibility.Visible) | |
End If | |
Return If(valueAux.HasValue AndAlso valueAux.Value, Visibility.Visible, Visibility.Hidden) | |
End Function | |
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack | |
Return Nothing | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment