如何multibinding得到一个父值 [英] How to get a parent value in multibinding
本文介绍了如何multibinding得到一个父值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用的DataTemplate
。这是模板:
<ItemsControl ItemsSource="{Binding RAM.Partitions}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Position, StringFormat={}{0}k}"/>
<Grid Grid.Column="1">
<Border>
<Border.Height>
<MultiBinding Converter="{StaticResource MultiplyConverter}">
<Binding ElementName="LayoutRoot" Path="ActualHeight"/>
<Binding Path="Size" />
<Binding Path="RAM.Size" />
</MultiBinding>
</Border.Height>
</Border>
</Grid>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
您可以看到这一行?
<Binding Path="RAM.Size" />
这行我抛出一个异常,应该是因为 RAM.Size
是从父元素。我怎么可能会得到价值?
That line throws me an exception, it should be because RAM.Size
is from a parent element. How might I get that value?
在此先感谢!
推荐答案
所以,你想要去的 RAM.Size
值相同的对象上,你的的ItemsControl
越来越其的ItemsSource
?
So you're trying to get to the RAM.Size
value on the same object that your ItemsControl
is getting its ItemsSource
from?
请参阅如果这个工程:
<MultiBinding Converter="{StaticResource MultiplyConverter}">
<Binding ElementName="LayoutRoot" Path="ActualHeight"/>
<Binding Path="Size" />
<Binding Path="DataContext.RAM.Size"
RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType=ItemsControl}" />
</MultiBinding>
因此,结合通过可视化树中上升到ItemsControl的,然后结合到其的DataContext的 Ram.Size
属性。
这篇关于如何multibinding得到一个父值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文