Возможно, buildbot был бы полезен http://buildbot.net/trac
Это то, что я сделал:
public class CombiningConverter : IValueConverter
{
public IValueConverter Converter1 { get; set; }
public IValueConverter Converter2 { get; set; }
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
object convertedValue = Converter1.Convert(value, targetType, parameter, culture);
return Converter2.Convert(convertedValue, targetType, parameter, culture);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
и называю это так:
<converters:CombiningConverter x:Key="negatedBoolToVisibilityConverter" Converter1="{StaticResource NegatedBooleanConverter}" Converter2="{StaticResource BoolToVisibilityConverter}" />
Я думаю, также можно использовать MultiValueConverter. Может, попробую позже.
В нашем проекте мы делаем обычный BooleanToVisibilityConverter, - сказал преобразователь. принимает один параметр (что угодно, строку, int, bool, что угодно). Если параметр установлен, он инвертирует результат, если нет, он выдает обычный результат.
public class BooleanToVisibilityConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool? isVisible = value as bool?;
if (parameter != null && isVisible.HasValue)
isVisible = !isVisible;
if (isVisible.HasValue && isVisible.Value == true)
return Visibility.Visible;
else
return Visibility.Collapsed;
}
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new System.NotImplementedException();
}
#endregion
}
Я только что создал то, что назвал ReversedBooleanToVisibilityConverter, чтобы делать то же самое, что и эти двое, но за один шаг.
To address this specific problem, instead of using two converters your could write your own BoolToVisibilityConverter that uses the ConverterParameter (as a bool) to determine whether or not to negate the original Boolean.
Personally I would just make 1 single converter that does the full conversion. Unless you desperately need the converters (like the negation) in other places, it will be easier to maintain (imo) if the conversion is done once, in one place.
Я думаю, вы можете использовать здесь мультиконвертер вместо двух отдельных преобразователей. У вас должна быть возможность повторно использовать логику существующих конвертеров. Для начала ознакомьтесь с этим обсуждением .