Une fois n'est pas coutume c'est moi qui pose une question
Bon alors, pour simplifier:
j'ai une classe Question qui représente les questions d'un quiz et qui contient une liste de propositions de réponses possibles.
Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 public class Question { public int Id { get; set; } public string Enonce { get; set; } public List<Proposition> Propositions { get; set; } } public class Proposition { public string Enonce { get; set; } public bool Bonne { get; set; } }
Je voudrais faire un UserControl qui affiche la liste des questions d'un quiz. Pour chaque question on affiche son Id (un textBlock), son enoncé (un textblock) et la liste des propositions sour forme de radiobutton.
Voici le code du UserControl
J'utilise un ItemsControl pour afficher les questions et un autre ItemsControl imbriqué pour les propositions de chaques questions.
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 <UserControl x:Class="QuizClient.UserControls.QuestionsControl" xmlns="<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation" target="_blank">http://schemas.microsoft.com/winfx/2...l/presentation</a>" xmlns:x="<a href="http://schemas.microsoft.com/winfx/2006/xaml" target="_blank">http://schemas.microsoft.com/winfx/2006/xaml</a>"> <Grid x:Name="LayoutRoot"> <ScrollViewer> <ItemsControl x:Name="icQuestions" ItemsSource="{Binding '', Path=''}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel x:Name="stackquestion" Margin="10" Orientation="Vertical" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Vertical"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Path=Id}"/> <TextBlock Text="{Binding Path=Enonce}"/> </StackPanel> <ItemsControl x:Name="icPropositions" ItemsSource="{Binding Propositions}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Margin="5" Orientation="Vertical" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <RadioButton GroupName="???????????" Content="{Binding Path=Enonce}"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </ScrollViewer> </Grid> </UserControl>
Tout cela fonctionne très bien, à un détail près: la propriété GroupName des radioButtons. Je voudrais affecter la même valeur (l'Id de la question) aux radioButtons d'une même question (d'une même liste de propositions).
Bref, quelle est la syntaxe du Binding à utiliser ? Les radioButton se trouvent dans un ItemsControl dont la source de données est la liste des propositions d'une question. Comment "remonter" à la question elle même pour en obtenir l'Id ?
Partager