Reputation: 5385
I have a wpf application using caliburn.micro. It has a datagrid and a combobox.
Here is the DataGrid:
<DataGrid x:Name="TriageMapRecords"
Grid.Row="0" Grid.ColumnSpan="5"
AutoGenerateColumns="False"
BaseControls:DataGridExtension.Columns="{Binding TriageMapRecordColumns}"
CanUserAddRows="False" IsReadOnly="True"
SelectedItem="{Binding Path=SelectedTriageMapRecord, Mode=TwoWay}">
SelectedTriageMapRecord object contains a field CounterpartyNameId.
I want to bind selected value in the combobox to CounterpartyNameId of the SelectedTriageMapRecord.
I tried this:
<ComboBox x:Name="RefCounterparties"
DisplayMemberPath="Name" SelectedValuePath="Id"
SelectedValue="{Binding Source=SelectedTriageMapRecord,
Path=CounterpartyNameId, Mode=TwoWay}"
Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left"
Width="Auto" MinWidth="100" Margin="3,3,0,3"/>
But this didn't work. Could you tell me what I am missing?
Upvotes: 1
Views: 1280
Reputation: 15237
It looks like you probably want to do it like this:
<ComboBox x:Name="RefCounterparties"
DisplayMemberPath="Name" SelectedValuePath="Id"
SelectedValue="{Binding SelectedTriageMapRecord.CounterpartyNameId,
Mode=TwoWay}"
Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left"
Width="Auto" MinWidth="100" Margin="3,3,0,3"/>
You don't want to set a source because your source is still the DataContext
. Then you specify the path on the DataContext
to drill down into. In this case, the SelectedTriageMapRecord
property of the DataContext
, and then the CounterpartyNameId
property of the SelectedTriageMapRecord
object.
Upvotes: 1