tags:

views:

50

answers:

1

Why isnt this selected value binding working? I am utterly confused here. When I load the page, the first text box properly shows the contents of 'SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID', in this case '20'.

What SHOULD happen is when the page is first loaded, the combobox should have the note with ID 20 preselected.

However, the combobox and the second text box are both empty (but the list of notes is populated). As soon as I selected an entry, the 2nd combobox is updated with the newly selected Note ID.

This only happens when the page is first loaded. As soon as I select a different SelectedComponentAnalysisViewModel it all works fine and the appropriate value is automatically selected in the combobox.

My only guess here is that somehow the combobox is trying to bind to the selected value before it is populated. Is there some way to force it to wait till its populated to bind? Or at least make it try to bind after it has been populated? Or maybe the reverese is happening and its trying to load before its datasource is loaded? But if that were the case, then I would expect the first text box to be empty.

(the text boxes are just there to help me debug this)

<ComboBox x:Name="ReactionEffectNoteSelector" ItemTemplate="{DynamicResource DataTemplate1}" ItemsSource="{Binding NoteViewModelList}" SelectedValuePath="NoteID" SelectedValue="{Binding SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID, Mode=OneWay}">
  <ComboBox.Resources>
    <DataTemplate x:Key="DataTemplate1">
      <TextBlock TextWrapping="Wrap" Text="{Binding NoteID, Mode=OneWay}"/>
    </DataTemplate>
  </ComboBox.Resources>         
</ComboBox>


<TextBlock HorizontalAlignment="Right" Text="{Binding SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID}"/>

<TextBlock HorizontalAlignment="Right" Text="{Binding SelectedValue, ElementName=ReactionEffectNoteSelector, Mode=OneWay}"/>
A: 

Why are you binding the SelectedValue to SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID and then setting SelectedValuePath to NoteID? That implies that there is a SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID.NoteID property.

I think you want to set SelectedValue set to SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.

HTH,
Kent

Kent Boogaart
Unfortunately thats not the issue. The problem is I am using NHibernate for everything. So the note in the list isn't actually equal to the note in the component analysis because NHibernate uses proxies for all of this. But the NoteIDs are unique so I compare those.The SelectedValuePath is set to NoteID because on the combobox side of things it is bound to a list of Notes and I need the NoteID. I don't believe SelectedValuePath has any impact on the binding path.I tested it to confirm, and if I make that change, the selected value stops working all together, not just on page load.
Justin