2009-08-23 6 views
14
<Button IsEnabled="{Binding (Not IsDisabled)}" /> 

¿Hay alguna manera de hacerlo con xaml puro, o tendré que hacerlo por código? PS. Hice la pregunta sabiendo que puedo crear un convertidor booleano como este:XAML 'NO' operador?

<ValueConversion(GetType(Boolean), GetType(Boolean))> 
Public Class BooleanFlagSwitchConverter : Implements IValueConverter 

    Public Function Convert(value As Object, targetType As Type, 
      parameter As Object, culture As CultureInfo) As Object 
      Implements IValueConverter.Convert 
     Return Not value 
    End Function 

    Public Function ConvertBack(value As Object, targetType As Type, 
      parameter As Object, ByVal culture As CultureInfo) As Object 
      Implements IValueConverter.ConvertBack 
     Return Not value 
    End Function 

End Class 

[ValueConversion(typeof(bool), typeof(bool))] 
public class BooleanFlagSwitchConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, 
     CultureInfo culture) 
    { 
     return !(bool)value; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, 
     CultureInfo culture) 
    { 
     return !(bool)value; 
    } 
} 
+0

Creo que esto es preferido

Respuesta

2

Yo recomiendo usar https://quickconverter.codeplex.com/

invirtiendo un valor lógico es tan simple como: <Button IsEnabled="{qc:Binding '!$P', P={Binding IsDisabled)}" />

que acelera el tiempo que normalmente se necesita para escribir convertidores.

+0

¿Funciona el enlace bidireccional para esta solución? –

+1

Sí, según la documentación del sitio que he vinculado anteriormente. Ejemplo: 'Height =" {qc: Enlace '$ P * 10', ConvertBack = '$ value * 0.1', P = {Ancho de prueba de enlace, Modo = TwoWay}} "' – Noxxys