MultiDataTrigger Binding to Collection and To a pr

2019-08-09 23:23发布

I have the following XAML:

<Style.Triggers>

  <MultiDataTrigger>
    <MultiDataTrigger.Conditions>
      <Condition Binding="{Binding Path=Errors, Converter={StaticResource ErrorsCountConverter}}">
        <Condition.Value>True</Condition.Value>
      </Condition> 
      <Condition Binding="{Binding Path=Errors[0].HasError}" Value="True" />
    </MultiDataTrigger.Conditions>
    <Setter Property="Background" Value="Red" />
  </MultiDataTrigger>

</Style.Triggers>

Errors is a ObservableCollection<BrokenRule>. The BrokenRule has a property called HasError. Now, I want to bind to that HasError property but not sure how to reference it in XAML.

1条回答
爷、活的狠高调
2楼-- · 2019-08-09 23:54

There is a relatively unknown forward-slash syntax for accessing a collection's current item. so if you want to bind to the current item of a data source you'd use "{Binding Path=/}" since you seem to want to automatically increment your Errors collection and have HasError respond accordingly you'd should be able to use something like "{Binding Path=Errors/HasError}" to get the HasErrors property of the current item in Errors.

Hope that helps!

查看更多
登录 后发表回答