WPF对象将自身发送为MultiBinding路径

时间:2009-11-23 21:16:02

标签: wpf data-binding hierarchicaldatatemplate multibinding

基本上我需要知道的是如何将HierarchicalDataTemplate的来源发送到绑定中,这就是我所拥有的:

<HierarchicalDataTemplate DataType="{x:Type myModel:Person}">
    <StackPanel Orientation="Horizontal">
        <Image Source="Images\User.gif" />
        <TextBlock Margin="5,0,0,0" Text="{Binding Name}" />
    </StackPanel>
    <HierarchicalDataTemplate.ItemsSource>
        <MultiBinding Converter="{StaticResource PersonConverter}">
            <Binding Path="Name" />
            <!-- Here I need something like Binding Path="Self" so I can send the source of the binding (the "Person" object) -->
        </MultiBinding>
    </HierarchicalDataTemplate.ItemsSource>
</HierarchicalDataTemplate>

所以我的源代码是myModel:Person类型的对象,我希望能够在MultiBinding中发送对象本身,以便PersonConverter可以使用它。

感谢您的帮助。

1 个答案:

答案 0 :(得分:12)

哇,我做了一个疯狂的疯狂猜测,它起作用了= S lol,这是解决方案

<MultiBinding Converter="{StaticResource PersonConverter}">
    <Binding Path="Name" />
    <Binding Path="." /> <!-- this sends the source of the binding -->
</MultiBinding>

谢谢!