Bonjour,

J'ai un objet qui contient des collections de différents types.
Pour chaque collection, je veux afficher le contenu et donner la possibilité d'ajouter ou d'enlever des items via un bouton ajouter et un bouton supprimer.
Comme le traitement est le même pour toutes les collections, il me semble évident qu'il doit y avoir moyen de faire un seul UserControl pour toutes les collections.

Le contenant est un objet et type minutes qui contient une collection de type, personnes, une collection de type anc_lots, une collection de type dossiers, ...
Un override string ToString() sur chaque type me permet de me contenter de lier l'itemsSource de la ListView directement à la collection.
Je passe l'objet Minute au UserControl via un DependencyProperty
Mais je me butte au problème du type d'objets contenus dans chaque collection.
Actuellement je ne peux pas me passer du type à 2 endroits :
1 : pour déterminer l'ItemsSource de la ListView (un ObservableCollection<personnes>)
2 : dans le DeleteBTN_Click

Je me dis qu'il n'est pas possible que je sois obligé de faire un UserControl pour chaque type, mais mes recherches restent infructueuses (mes clés de recherches ne seraient-elles pas les bonnes ?).
Comment pourrais-je faire pour "généraliser" le type qui est traité ?

Voici mon UserControl :
Code XAML : 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    <UserControl.Resources>
       <Style x:Key="alternatingStyle" TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="White"></Setter>
                </Trigger>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="LightCyan"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>
            <ListView Name="LV"
                      Grid.Column="0" 
                      MinWidth="250"
                      MinHeight="20"
                      MaxHeight="200"
                      VerticalAlignment="Top"
                      ItemContainerStyle="{StaticResource alternatingStyle}" 
                      AlternationCount="2"
                      ItemsSource="{Binding Path=LVItemsSource}"/>
        <StackPanel x:Name="ButtonsSP" 
                    Grid.Column="1" 
                    Orientation="Vertical" 
                    Visibility="{Binding ButtonsSPVisibility}">
            <Button Name="AddLotBTN"
                    Content="Ajouter"
                    Margin="10"
                    Click="AddLotBTN_Click" />
            <Button Name="DeleteBTN"
                    Content="Supprimer"
                    Margin="10"
                    Click="DeleteBTN_Click" />
        </StackPanel>
        <Grid Name="SelectionContainer" 
              Grid.Column="2" />
    </Grid>
</UserControl>
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    public partial class PropriosSelectUC : UserControl, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
 
 
        private void OnPropertyChanged(string info)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(info));
        }
        public Actions Action
        {
            get { return (Actions)GetValue(ActionProperty); }
            set { SetValue(ActionProperty, value); }
        }
 
 
        //Using a DependencyProperty as the backing store for Action.This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ActionProperty =
            DependencyProperty.Register("Action", typeof(Actions), typeof(PropriosSelectUC), new PropertyMetadata(null));
 
 
        public minutes Minute
        {
            get { return (minutes)GetValue(MinuteProperty); }
            set { SetValue(MinuteProperty, value); }
        }
 
 
        // Using a DependencyProperty as the backing store for Minute.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MinuteProperty =
            DependencyProperty.Register("Minute", typeof(minutes), typeof(PropriosSelectUC), new PropertyMetadata(null));
 
 
        public ObservableCollection<personnes> LVItemsSource
        {
            get { return new ObservableCollection<personnes>(Minute.personnes); }
        }
 
 
        public PropriosSelectUC()
        {
            InitializeComponent();
            DataContext = this;
        }
 
 
        public PropriosSelectUC(Actions action)
        {
            InitializeComponent();
            DataContext = this;
            Action = action;
        }
 
 
        public Visibility ButtonsSPVisibility
        {
            get
            {
                //if (Action == Actions.Consult)
                //    return Visibility.Collapsed;
                //else
                    return Visibility.Visible;
            }
        }
 
 
 
 
        private void AddLotBTN_Click(object sender, RoutedEventArgs e)
        {
 
 
        }
 
 
        private void DeleteBTN_Click(object sender, RoutedEventArgs e)
        {
            foreach(personnes pers in LV.SelectedItems)
                Minute.personnes.Remove(pers);
            OnPropertyChanged("LVItemsSource");
        }
    }