I have typical case of nested collections. I have to make a questionary form. I have ObservableCollection
of Questions that are part of the questionary. For each question, according to the question type, I have to display answers. Thus need to create template for nested binding. How can I do that?
Objects:
Question
Question
Answers
Here is part of my code:
<ListView ItemsSource="{Binding Path=ocQuestions, Mode=TwoWay}" x:Name="lvQuestions" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel DockPanel.Dock="Top" Background="#FF3C3C3C">
<StackPanel>
<StackPanel.Style>
<Style TargetType="StackPanel">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Type}" Value="B">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
<ListView DataContext="{Binding SelectedItem, ElementName=lvQuestions}" ItemsSource="{Binding Answers}">
<Label Style="{StaticResource CampaignAnswer}" >
<CheckBox Content="{Binding Answer}"/>
</Label>
</ListView>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>