Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind to Parent Object Property with RelativeSource

I've built a WPF based Treeview with

Item
-Subitem

If Subitem is selected, I would like to display also Properties of Item.

<StackPanel Grid.Column="2" DataContext="{Binding ElementName=myTreeView, Path=SelectedItem}">
  <TextBox Text="{Binding Path=Name, Mode=TwoWay}" />
  <TextBox Text="{Binding RelativeSource={???} Path=Name, Mode=TwoWay}" />
</StackPanel>

I guess I need to use a RelativeSource statement, but not quite sure how to do so.

like image 871
Stef Avatar asked Nov 18 '25 07:11

Stef


1 Answers

 {Binding RelativeSource={RelativeSource AncestorType={x:Type typeOfAncestor}}, Path=Name, Mode=TwoWay}
like image 71
opewix Avatar answered Nov 20 '25 22:11

opewix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!