Reputation: 54
I have a class named Order
with properties of ID
and Name
.
I have an ObservableCollection<Order>
named AllOrder
.
I have a ComboBox
<ComboBox Name="CID" DataContext="{Binding ElementName=MainScreen}"
ItemsSource="{Binding AllOrder}" DisplayMemberPath="ID"/>
When I select the ComboBox
I want TextBox
to display Name
, something like:
<TextBox Text="{Binding ElementName=CID,Path=SelectedItem,Display=Name}">
Upvotes: 0
Views: 591
Reputation: 169150
You can bind to nested properties:
<TextBox Text="{Binding ElementName=CID, Path=SelectedItem.Name}" />
SelectedItem
returns the currently selected Order
object and .Name
returns the value of the Name
property of this one.
Upvotes: 3