Problème DataTemplate dans un DataTemplate (Path)
Bonjour,
Je vous explique mon problème. Voici l'architecture de mon projet :
Class Category qui implémente INotifyPropertyChanged avec 2 propriétés : StackPanelName et ListBoxName.
Class Categories avec une méthode GetTest qui retourne une IList<Category>
Class Subject qui implémente INotifyPropertyChanged avec 1 propriété : Name.
Class Subjects avec une méthode GetTest qui retourne une IList<Subject>
Class ViewModel qui implémente INotifyPropertyChanged avec un event et une méthode.
Class CoursesViewModel qui herite de ViewModel avec :
- Une propriété ItemsListBoxSubject1 de type ObservableCollection<Subject>
- Une propriété ItemsListBoxCategories de type ObservableCollection<Category>
- Dans le constructeur, je set mes 2 propriétés avec un ObservableCollectionConverter qui me convertit mes IList en ObservableCollection :
Code:
1 2
| this.ItemsListBoxCategories = ObservableCollectionConverter.GetObservableCollection<Category>(Categories.GetTest());
this.ItemsListBoxSubject1 = ObservableCollectionConverter.GetObservableCollection<Subject>(Subjects.GetTest()); |
Et enfin dans mon code xaml j'ai 2 listBox avec des datatemplate :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <ListBox ItemsSource="{Binding Path=ItemsListBoxCategories, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="{Binding Path=StackPanelName}" Height="32">
<StackPanel>
<StackPanel.Background>
<ImageBrush ImageSource="Images/t4.jpg" />
</StackPanel.Background>
</StackPanel>
</StackPanel>
<ListBox x:Name="{Binding Path=ListBoxName}" ItemsSource="{Binding Path=ItemsListBoxSubject1, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource TextBlockMenuStyle}" Height="20" Text="{Binding Path=Name, Mode=TwoWay}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox> |
Le soucis c'est que l'ItemSource de ma deuxieme ListBox ne semble pas avoir le bon Path. Lors de la compilation j'ai une page blanche.
En effet, ItemsListBoxSubject1 n'est pas une propriété de ma classe category comme StackPanelName ou ListBoxName mais le nom de ma propriété dans ma classe CoursesViewModel de type ObservableCollection<Subject>.
J'ai essayé de mettre juste la première listbox, ou juste la deuxieme pour vérifier si le binding marchait. Cela marche très bien. C'est lorsque je les "imbrique" que y'a soucis.
J'ai essayé d'être le plus clair possible. Merci d'avance pour votre aide.
Cordialement.