2

I'd like to use the ItemsSource property from a particular element as one of the bindings in another element's MultiBinding. Here's what I have so far:

<Label>
  <Label.Content>
    <MultiBinding Converter="{converters:myMultiValueConverter}">
      <Binding Path="PageIndex" />
      <Binding ElementName="anotherElement" Path="ItemsSource"/>
    </MultiBinding>
  </Label.Content> 
</Label>

This works once (when the ItemsSource is initially set), but the binding fails to update when the ObservableCollection bound to the original element's ItemsSource property has items added or removed. Is this kind of binding possible?

4

1 回答 1

5

像这样添加一个虚拟绑定(-您不需要该值-)以强制MultiBinding重新评估:

<Binding ElementName="anotherElement" Path="ItemsSource.Count"/>

编辑:刚刚注意到一个缺陷:如果您移动不会注册的项目,如果这不会改变Count其间的属性,那么这可能与您有关。在这种情况下,您可以绑定到您自己的虚拟对象,您可以针对该虚拟对象触发更改通知CollectionChanged(尽管在任何情况下都不是那么干净)。

您可能需要考虑 HighCore 的建议,一个get仅返回计算值的属性,您PropertyChanged在它所依赖的所有位置手动触发该值通常非常方便。

于 2013-07-18T21:10:44.287 回答