Oliver Hanappi
Oliver Hanappi

Reputation: 12346

How can I achieve a binding path which is bound by another binding?

I'm writing my own UserControl which displays data in a ListBox. I want to achieve something similar to a property like "DisplayMemberPath". In my example, it's "EditableMemberPath", which should determine which member will be displayed in the textbox. However, using a binding on a binding does not work.

<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>

Can you help me finding a proper solution?

Best Regards
Oliver Hanappi

Upvotes: 0

Views: 178

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292705

You can't do that directly in XAML (at least not with the built-in classes) : a Binding is not a DependencyObject, so you can't bind its properties.

However the post mentioned by Martin Harris looks promising...

Upvotes: 1

Related Questions