Pass variable through the ConverterParameter

1

I have the following code snippet:

Visibility = "{Binding TipoDestinatario, Converter={StaticResource conversorTipoDestinatario}, ConverterParameter=}.

I would need to pass a Boolean variable by ConverterParameter= , would anyone know how to do it?

    
asked by anonymous 08.12.2014 / 11:08

1 answer

1

Your Hat, so far I have not been able to use Binding for the ConverterParameter. Since you need to pass a variable, a viable suggestion is to use MultiBinding:

XAML

<Label x:Name="situacaoPedidoLabel" Width="200" Margin="10,0" VerticalAlignment="Center" Content="Situação">
    <Label.Visibility>
        <MultiBinding Converter="{StaticResource VisibilidadePedidoConverter}">
            <MultiBinding.Bindings>
                <Binding Path="Pedido.Situacao" />
                <Binding Path="PodeFecharPedido" />
            </MultiBinding.Bindings>
        </MultiBinding>
    </Label.Visibility>
</Label>

Converter

using System;
using System.Windows.Data;

namespace CSharp2.Capitulo10.Wpf.Produtos.Converters
{
    public class VisibilidadePedidoConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                var podeVisualizar = (System.Convert.ToInt32(values[0]) == 1) && System.Convert.ToBoolean(values[1]);

                return podeVisualizar ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden;
            }
            catch 
            {
                return System.Windows.Visibility.Visible;
            }
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException("Not implemented");
        }
    }
}
    
08.12.2014 / 13:41