Bonjour à tous,
J'ai implémenté une interface avec MVVM light qui fonctionne bien, mais je me retrouve dans un cas de figure compliqué.
C'est un formulaire qui exploite un objet "Projet".
Le Contexte :
- Mon "projet" peut avoir des "intervenants" => Géré dans un ViewModelPro.
- Un intervenant est composé d'un "type d'intervenant" et d'un "contact" => Géré dans un ViewModelInt.
La Forme :
- Dans mon formulaire, J'ai une ListView pour afficher mes "intervenants" liés.
- Un item de la liste est composé d'une ComboBox (type d'intervenant) et d'un AutoCompleteBox (Contact).
Les Questions :
- Comment faire communiquer les 2 composants (ComboBox et AutoCompleteBox) pour que :
1. L'AutoCompleteBox se charge avec comme filtre l'élément choisit dans la ComboBox ?
2. Lorsque la ComboBox fait un SelectionChanged, l'AutoCompleteBox se remette à null ?
Aujourd'hui, j'ai ça :
Et mon code :
Code : 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 <Resources> <DataTemplate x:Key="lvTemplateInt"> <Border> <WrapPanel> <ComboBox x:Name="cbTypesInt" ItemsSource="{Binding Interv.ElmtsTypes.items, Source={StaticResource Locator}}" SelectedValue="{Binding typeInt, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Mode=TwoWay}"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged" > ??? Quoi mettre pour réinitialiser acInterv ??? </i:EventTrigger> </i:Interaction.Triggers> </ComboBox> <Toolkit:AutoCompleteBox x:Name="acInterv" SelectedItem="{Binding contact, Mode=TwoWay}" Populating="acInterv_Populating"> <Toolkit:AutoCompleteBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <Label Content="{Binding .}" /> </StackPanel> </DataTemplate> </Toolkit:AutoCompleteBox.ItemTemplate> </Toolkit:AutoCompleteBox> </WrapPanel> </Border> </DataTemplate> </Resources> ... <ListView x:Name="lvInterv" ItemsSource="{Binding ElmtInfo.intervenants}" ItemTemplate="{StaticResource lvTemplateInt}"/>
Avez vous une idée ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 private void acInterv_Populating(object sender, PopulatingEventArgs e) { AutoCompleteBox acb = sender as AutoCompleteBox; if ((acb != null) && (!string.IsNullOrEmpty(e.Parameter)) && (e.Parameter.Length > 3)) { var vmInts = Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<ViewModelIntervs>(); var IntervTypeIdSel = ???// Essai de récupérer le type choisit dans la ComboBox vmInts.GetAllCommand.Execute(IntervTypeIdSel); if (vmInts.Elmts?.items?.Count > 0) { acb.ItemsSource = vmInts.Elmts?.items; acb.PopulateComplete(); } } }
Partager