MultiDataTrigger Binding to Collection and To a property within the collection

喜夏-厌秋 提交于 2019-12-11 13:24:10

问题


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:


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!



来源:https://stackoverflow.com/questions/2164274/multidatatrigger-binding-to-collection-and-to-a-property-within-the-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!