1 pièce(s) jointe(s)
ComboBox ItemTemplate Error lors de la sélection
Bonjour à tous,
J'ai créé un ComboBox de la manière suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <StackPanel Margin="5,0,5,0">
<TextBlock Text="Ajoutez un ingrédient" HorizontalAlignment="Center"/>
<ComboBox ItemsSource="{Binding IngredientListeSource}"
SelectedItem="{Binding SelectedIngredient}"
IsEditable="True" IsTextSearchCaseSensitive="False">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}"/>
<TextBlock Text=" ("/>
<TextBlock Text="{Binding IDmesure}"/>
<TextBlock Text=")"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</StackPanel> |
L'ItemsSource est bien chargé (aucun soucis).
Le point bloquant vient lors de la sélection d'un "item" (comme vous pouvez le voir sur l'image ci-dessous)
Pièce jointe 560880
La propriété SelectedIngredient du ViewModel est la suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| private Ingredient _selectedIngredient;
public Ingredient SelectedIngredient
{
get
{
return _selectedIngredient;
}
set
{
_selectedIngredient = value;
OnPropertyChanged("SelectedIngredient");
}
} |
L'itemsSource du ComboBox est bindé sur une ObservableCollection qui récupère ses données via la fonction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| private List<Ingredient> getIngredientListeSource()
{
List<Ingredient> itemListe = new List<Ingredient>();
foreach (var item in IngredientProvider.selectAll())
{
itemListe.Add(new Ingredient
{
Name = item.Name,
IDmesure = item.IDmesure,
});
}
return itemListe;
} |
Je ne trouve pas d'où peut venir le problème.
Je cale pour ce soir :koi:
Auriez-vous une petite idée ?