コード例 #1
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            VisibilityAsBooleanConverterOptions options = GetOptions(parameter);

            object[] input = new object[values.Length];
            for (int i = 0; i < values.Length; i++)
            {
                bool?b = GetBool(values[i]);
                if (b != null)
                {
                    input[i] = b.Value;
                }
                else
                {
                    return(null);
                }
            }

            LogicalConversionOptions logicalOptions = LogicalConversionOptions.None;

            if (options.HasFlag(VisibilityAsBooleanConverterOptions.CombineWithAnd))
            {
                logicalOptions |= LogicalConversionOptions.CombineWithAnd;
            }
            else
            {
                logicalOptions |= LogicalConversionOptions.CombineWithOr;
            }

            if (options.HasFlag(VisibilityAsBooleanConverterOptions.Negate))
            {
                logicalOptions |= LogicalConversionOptions.Negate;
            }

            bool boolean = (bool)this.logicalConverter.Convert(input, null, logicalOptions, culture);

            return(GetVisibility(boolean, options));
        }
コード例 #2
0
 private static Visibility GetVisibility(bool boolValue, VisibilityAsBooleanConverterOptions options)
 {
     if (boolValue)
     {
         return(Visibility.Visible);
     }
     else if (options.HasFlag(VisibilityAsBooleanConverterOptions.UseHidden))
     {
         return(Visibility.Hidden);
     }
     else
     {
         return(Visibility.Collapsed);
     }
 }
コード例 #3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool?b = GetBool(value);

            if (b != null)
            {
                VisibilityAsBooleanConverterOptions options = GetOptions(parameter);

                if (options.HasFlag(VisibilityAsBooleanConverterOptions.Negate))
                {
                    b = !b.Value;
                }

                return(GetVisibility(b.Value, options));
            }

            return(null);
        }