I have a MultiBinding
converter that determines the visibility of a control depending on if both of my Binding fields evaluate to true. If for some reason it can't reach either of these bool properties, I want to set them to evaluate to true. For example:
The code that I currently have is:
<MultiBinding Converter="{StaticResource AndToVisibilityConverter1}" FallbackValue="Visible">
<Binding Path="IsConnected" FallbackValue="true" />
<Binding Path="CurrentUser.IsConsumerOnlyAgent" Converter="{StaticResource InvertedBooleanConverter1}" FallbackValue="True" />
</MultiBinding>
The code runs fine, however I get the error message in my IDE's output that indicates:
System.Windows.Data Error: 11 : Fallback value 'True' (type 'String') cannot be converted for use in 'Visibility' (type 'Visibility'). BindingExpression:Path=IsConnected; DataItem=null; target element is 'StackPanel' (Name='');
Which I've pinpointed to this converter and verified it is where the XAML error is. Sorry for the ignorance here, but is there a way to possibly set the FallbackValue to each of these bindings to evaluate to "true" upon failure to obtain the set path? Thanks in advance
Update:
Here's the code for my Visibility Converter (I use this in several places throughout my app, just want to add fallback values):
internal class AndToVisibilityConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
return Visibility.Collapsed;
foreach (var value in values)
{
if (value == null || !(value is bool))
return Visibility.Collapsed;
if (!((bool) value))
return Visibility.Collapsed;
}
return Visibility.Visible;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}