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 开发者_JAVA技巧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}"/>
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
.
精彩评论