Bonjour,
j'ai montré ta question à un collègue qui connait bien WPF.
Voici sa proposition:
Deux classes:
public class aliment
{
public aliment(string Nom)
{
this.Nom = Nom;
LP = new List<produit>();
}
public List<produit> LP { get; set; }
public string Nom { get; set; }
public override string ToString()
{
return Nom;
}
}
public class produit
{
public string name { get; set; }
public produit() { }
public produit(string s) { name = s; }
public override string ToString()
{
return name;
}
}
Le xaml (la couleur c'est juste pour que ça tranche)
<Grid Name="Grid_Infos" Background="#FF4A4848">
<ListBox x:Name="LBox2" ItemsSource="{Binding ElementName=LBox, Path=SelectedItem.LP}" Margin="258,0,0.4,-0.2" Background="#FFD2D2F2" ></ListBox>
</Grid>
<ListBox x:Name="LBox" Margin="0,0,293.4,-0.2"></ListBox>
Et le code behind dans Windows_Loaded
produit p1 = new produit("orange");
produit p2 = new produit("pomme");
produit p3 = new produit("tomate");
produit p4 = new produit("salade");
aliment temp = new aliment("Fruits");
aliment toto = new aliment("Légumes");
temp.LP.Add(p1);
temp.LP.Add(p2);
toto.LP.Add(p3);
toto.LP.Add(p4);
LBox.Items.Add(temp);
LBox.Items.Add(toto);
Quand j'étais petit, la mer Morte n'était que malade.
George Burns
18 janv. 2016 à 21:27
Je vais travailler avec cela sur mon projet.