<TextBlock.Visibility>
<mat:MatcherConverter>
<mat:Matcher MatchVisibility="Visible" DismatchVisibility="Collapsed">
<mat:Matcher Value1="{Binding Boolean1}" Value2="True" ComparisonOperator="AND"/>
<mat:Matcher Value1="{Binding Boolean2}" Value2="True" ComparisonOperator="AND"/>
</mat:Matcher>
</mat:MatcherConverter>
</TextBlock.Visibility>
您如何看待将MarkupExtension作为基类的类? 在这种情况下,它将是MatcherConverter。这个类将以递归方式遍历所有匹配器,结果是布尔值。
答案 0 :(得分:0)
您可以在TheBooleanResult
中创建一个属性Matcher
,而不是返回您要评估的布尔结果(在Children
和Value1
,Value2
,... )。然后创建一个IValueConverter
,其Matcher
并获取TheBooleanResult
并返回您想要的可见性。
public class MatcherConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Matcher m = (Matcher)value;
return m.TheBooleanResult ? Visibility.Visible : Visibility.Hidden;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}