XAML绑定索引运算符

时间:2016-03-08 10:34:30

标签: c# wpf xaml

是否可以从包含数组本身的数据上下文绑定[]运算符内的值?

我设法在我希望与此绑定绑定的元素中获取正确的索引:

Binding DataContext.INDEX_ID, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:UCIndexByClientKeyMeasure}}

INDEX_ID给出正确的整数

但我无法让这个索引在另一个绑定中运行。我试过了:

Binding .[{Binding  DataContext.INDEX_ID,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:UCIndexByClientKeyMeasure}}}]

当我通过一个satic值,如:

Binding .[10]

然后它有效。

由于

1 个答案:

答案 0 :(得分:0)

MultiBinding确实......谢谢

<MultiBinding Converter="{StaticResource clientIndexConverter}" StringFormat="N2">
    <Binding Path="DataContext.INDEX_ID" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:UCIndexByClientKeyMeasure}}" ></Binding>
    <Binding Path="."></Binding>
</MultiBinding>