代码之家  ›  专栏  ›  技术社区  ›  Oliver Hanappi

如何实现由另一个绑定绑定绑定的绑定路径?

  •  0
  • Oliver Hanappi  · 技术社区  · 15 年前

    我正在编写自己的用户控件,它在列表框中显示数据。我想实现类似于“DisplayMemberPath”的属性。在我的示例中,它是“editablememberpath”,它应该决定在文本框中显示哪个成员。但是,在绑定上使用绑定不起作用。

    <ListBox ItemsSource="{Binding Path=Items, ElementName=me}"
             SelectedItem="{Binding Path=SelectedItem, ElementName=me}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <Image Source="{Binding Converter={Binding Path=ItemToImageConverter, ElementName=me}}" />
    
                    <TextBlock Text="{Binding Path={Binding Path=EditableMemberPath, ElementName=me}}" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    你能帮我找到一个合适的解决办法吗?

    最好的问候
    奥利弗哈纳皮

    1 回复  |  直到 15 年前
        1
  •  1
  •   Thomas Levesque    15 年前

    不能在XAML中直接这样做(至少不能在内置类中这样做):a Binding 不是一个 DependencyObject ,因此无法绑定其属性。

    然而,马丁·哈里斯提到的这篇文章看起来很有前途…