Value Converter Group crashes build tool
I am trying to integrate a value converter group so that I can invert a bool and then convert the result to a visibility. When I add the following to my xaml the build tool crashes Unity at startup:
The code for the converter:
Code: Select all
<common:ValueConverterGroup x:Key="invertBoolAndChangeVisibilityConverter">
<common:InvertBoolConverter/>
<common:BoolToVisibilityConverter/>
</common:ValueConverterGroup>
Code: Select all
public class ValueConverterGroup : List<IValueConverter>, IValueConverter
{
public object Convert (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return this.Aggregate (value, (current, converter) => converter.Convert (current, targetType, parameter, culture));
}
public object ConvertBack (object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException ();
}
}
-
-
sfernandez
Site Admin
- Posts: 2097
- Joined:
Re: Value Converter Group crashes build tool
The crash comes from using a converter (IValueConverter) that also implements another interface (IList).
We don't support objects implementing multiple interfaces, but we should warn the user without crashing this way, we will fix this.
You can achieve the same result by using a property to contain children converters:
We don't support objects implementing multiple interfaces, but we should warn the user without crashing this way, we will fix this.
You can achieve the same result by using a property to contain children converters:
Code: Select all
[System.Windows.Markup.ContentProperty("Children")]
public class ValueConverterGroup : IValueConverter
{
public List<IValueConverter> Children { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
object current = value;
foreach (var converter in Children)
{
current = converter.Convert(current, targetType, parameter, culture);
}
return current;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Who is online
Users browsing this forum: No registered users and 1 guest