System.Windows.Controls.TypeToVisibilityConverter.Convert C# (CSharp) Method

Convert() public method

Converts the value parameter to a visibility value.
public Convert ( object value, Type targetType, object parameter, CultureInfo culture ) : object
value object The value that is to be converted.
targetType Type The type to which the value is to be converted. In this case it is always visibility.
parameter object A parameter that determines the value to which the value has to be equal to return visible.
culture System.Globalization.CultureInfo The culture information of the current culture, so that parsing can be adjusted to cultural conventions.
return object
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // Checks if the value provided is null, if so then tell the converter that the value is unset
            if (value == null)
                return DependencyProperty.UnsetValue;

            // Gets the value as type and check if it is null, if so then tells the converter, that the type of the object is used
            Type typeValue = value as Type;
            if (typeValue == null)
                typeValue = value.GetType();

            // Gets the parameter and check if it is null, if so then tells the converter, that the value is unset
            Type parameterValue = parameter as Type;
            if (parameterValue == null)
                return DependencyProperty.UnsetValue;

            // If the parameter equals the value that is to be converted, then returns visible, otherwise hidden is returned
            return typeValue == parameterValue ? Visibility.Visible : Visibility.Collapsed;
        }
TypeToVisibilityConverter