一种更复杂的方法(但也更可重用)是将 aDataTrigger
与 aMultiBinding
和 a一起使用IMultiValueConverter
:
public class EqualsConverver : IMultiValueConverter
{
public object Convert(object[] values, Type targetType,
object parameter, CultureInfo culture)
{
if (values.Length < 1)
return Binding.DoNothing;
var obj = values[0];
for (int i = 1; i < values.Length; ++i)
{
if (!obj.Equals(values[i]))
return false;
}
return true;
}
public object[] ConvertBack(object value, Type[] targetTypes,
object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
然后你的触发器看起来像:
<DataTrigger Value="True">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource equalsConverter}">
<Binding Path="Value" RelativeSource="{RelativeSource Self}" />
<Binding Path="Maximum" RelativeSource="{RelativeSource Self}" />
</MultiBinding>
</DataTrigger.Binding>
<Setter Property="Visibility" TargetName="Animation" Value="Collapsed"/>
</DataTrigger>