How to pass a ternary as a binding in XAML

0

Hello, I'm creating a convert to a XAML application. The idea is that based on this convert I can return the value of the property Visibility to any UserControl or return the default value as you can see in that link :

public class VisibleConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if ((value is string & string.IsNullOrEmpty((string)value)) |
            (value is bool & !!(bool)value) | 
            (value != null))
            return Visibility.Visible;

        return null;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

The intention is that I can pass both a string and check if it is empty or else pass a boolean or any other element and check if it is null, having as failback or a Visibility.Hidden or Visibility.Collapsed .

My question then is. Is there any way that directly in the properties of my UserControl I can pass a Ternary (Boolean) validation, What I look for would look something like this:

<Window x:Class="Test.Window"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <Grid>
        /* aqui é onde quero fazer a validação direta no binding*/
        <TextBlock Text="Visivel" 
                   Visibility="{Binding (2 == 2), 
                                Converter={StaticResource VisibleConverter}, 
                                FallbackValue=Collapsed}" />
    </Grid>
</Window>

Is there any way to pass this tenant condition directly to XAML?

    
asked by anonymous 26.06.2018 / 16:46

0 answers