This question relates to this question.
I have a EF model like this.
Using Silverlight 4 I have an application showing questions to the user, defined through the QuestionSet. If a question has more than one answer alternative, a ComboBox is rendered. If only one alternative is given, a TextBox is rendered, in which the user can put freetext.
All user answers are stored in PersonQA entities. But herein lies the question: When the TextBox is rendered, I am not able to find the correct path and bind to the property "AnswerFreetext" (in PersonQA). What am I doing wrong?
XAML:
<ListBox x:Name="QAListBox" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectedIndex="-1" ItemsSource="{Binding Questions}" IsTabStop="True" TabIndex="5" ScrollViewer.HorizontalScrollBarVisibility="Auto" Margin="10" BorderThickness="0"> <ListBox.Resources> <fx:EqualityToVisibilityConverter x:Key="converter" TrueValue="Visible" FalseValue="Collapsed" /> <fx:CollectionToFirstElementConverter x:Key="collectiontoitem" /> </ListBox.Resources> <ListBox.ItemTemplate> <DataTemplate> <Grid d:DesignWidth="931" d:DesignHeight="61" d:IsLocked="True" Margin="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width=".80*" MinWidth="800"/> <ColumnDefinition Width=".20*" MinWidth="200"/> </Grid.ColumnDefinitions> <TextBlock Text="{Binding Path=QuestionText}" Padding="10" FontSize="21.333" FontWeight="Bold" Margin="0" Grid.Column="0" d:IsLocked="True" /> <ComboBox ItemsSource="{Binding AnswerAlternative, Mode=OneWay}" SelectedValuePath="AnswerAlternativeId" DisplayMemberPath="AnswerText" FontSize="21.333" FontWeight="Bold" Grid.Column="1" Margin="60,0,0,0" d:IsLocked="True" SelectionChanged="ComboBox_SelectionChanged" Visibility="{Binding Path=AnswerAlternative.Count, Converter={StaticResource converter}, ConverterParameter=2}"> </ComboBox> <TextBox Grid.Column="1" Margin="60,0,0,0" Text="{Binding Path=PersonQA.AnswerFreetext, Mode=TwoWay}" Visibility="{Binding AnswerAlternative.Count, Converter={StaticResource converter}, ConverterParameter=1}" /> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
The XAML has a ViewModel class as DataContext, which exposes Questions IEnumerable.
t.