Salut
Je fais actuellement une app WPF respectant le pattern MVVM (sans framework, j'ai implémenté le code de Josh Smith).
Tout fonctionne sauf le Command={Binding LoadFuncCommand}.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 <ListView HorizontalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Row="1" BorderThickness="0" Margin="0,2,0,0" VerticalAlignment="Stretch" Background="{x:Null}" ItemsSource="{Binding OpenedWindows}"> <ListView.ItemTemplate> <DataTemplate> <Button VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ToolTip="{Binding Path=Header}" Command="{Binding LoadFuncCommand}" CommandParameter="{Binding Path=Id}"> <Image Source="{Binding Path=Thumbnail}"/> </Button> </DataTemplate> </ListView.ItemTemplate> </ListView>
J'ai un accesseur dans mon ViewModel : public ICommand LoadFuncCommand, initialisé comme pour toutes les commandes de mon projet.
Cependant, lorsque je clique sur le bouton, la commande n'est pas exécutée. (j'ai mis un pauvre MessageBox.Show("coucou") pour tester)
J'ai essaye d'ajouter dans ma classe d'items un ICommand OnClickCommand et de remplacer mon binding par :
De cette façon, la commande définie dans OnClickCommand est appelée.
Code : Sélectionner tout - Visualiser dans une fenêtre à part Command="{Binding Path=OnClickCommand}"
J'en déduis que le datacontext du button est l'item actuel de la liste OpenedWindows... et donc, logiquement, il ne trouve pas LoadFuncCommand ?
Comment je fais pour spécifier au button de reprendre - juste pour le Command={Binding ...} - le datacontext de l'usercontrol et non pas de l'item ?
Merci,
Dotixx
Partager