Created
June 22, 2014 10:39
-
-
Save wtuts/d63e0b8dfb2d226fccf1 to your computer and use it in GitHub Desktop.
boolean to visibility converter class
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
public class BooleanToVisibilityConverter : IValueConverter | |
{ | |
//Set to true if you want to show control when boolean value is true | |
//Set to false if you want to hide/collapse control when value is true | |
private bool triggerValue = false; | |
public bool TriggerValue | |
{ | |
get { return triggerValue; } | |
set { triggerValue = value; } | |
} | |
//Set to true if you just want to hide the control | |
//else set to false if you want to collapse the control | |
private bool isHidden; | |
public bool IsHidden | |
{ | |
get { return isHidden; } | |
set { isHidden = value; } | |
} | |
private object GetVisibility(object value) | |
{ | |
if (!(value is bool)) | |
return DependencyProperty.UnsetValue; | |
bool objValue = (bool)value; | |
if ((objValue && TriggerValue && IsHidden) || (!objValue && !TriggerValue && IsHidden)) | |
{ | |
return Visibility.Collapsed; | |
} | |
if ((objValue && TriggerValue && !IsHidden) || (!objValue && !TriggerValue && !IsHidden)) | |
{ | |
return Visibility.Collapsed; | |
} | |
return Visibility.Visible; | |
} | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
return GetVisibility(value); | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
throw new NotImplementedException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment