Bonjour à tous !

Je suis bloqué dans mon code, je n'arrive pas à trouver comment récupérer plusieurs textbox en une fois.

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
<Window x:Class="Isia.AddClassIsia.FileNameDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Ajouter une classe" Height="auto" Width="431" ResizeMode="CanResize" ShowInTaskbar="True" WindowStartupLocation="CenterScreen" SizeToContent="WidthAndHeight">
 
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="26" />
            <RowDefinition Height="26" />
            <RowDefinition Height="26" />
            <RowDefinition Height="26" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition />
            <ColumnDefinition Width="auto" />
        </Grid.ColumnDefinitions>
 
        <Label Grid.Row="0" Grid.Column="0" Name="lblFolder" Content="Nom de la classe:" HorizontalAlignment="Left" Margin="5 0 0 0" VerticalAlignment="Center" Height="26" FontWeight="SemiBold" />
        <TextBox Grid.Row="0" Grid.Column="1" Name="txtName" VerticalContentAlignment="Center" Height="26" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Stretch" MinWidth="210"/>
        <Button Grid.Row="0" Grid.Column="3" Content="Ajouter" HorizontalAlignment="Center" Margin="10,0" VerticalAlignment="Center" Width="75" Height="26" IsDefault="True" Name="btnCreate" Click="Button_Click" />
 
            <Button Grid.Row="1" Grid.Column="0" Content="Ajouter une autre classe" HorizontalAlignment="Left" Margin="10,0" VerticalAlignment="Center" Width="auto" Height="26" IsDefault="False" Name="btnMoreClass" Click="BtnMoreClass_Click" />
            <Button Grid.Row="1" Grid.Column="3" Content="Valider" HorizontalAlignment="Left" Margin="10,0" VerticalAlignment="Center" Width="auto" Height="26" IsDefault="False" Name="btnLessClass" Click="BtnLessClass_Click" />
 
        <StackPanel Name="someStackPanel" Grid.Row="2" Grid.ColumnSpan="2" >
        </StackPanel >
 
        <CheckBox x:Name="LiaisionTable" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="5,0,0,0" Content="Table de liaison (Ne pas cocher si ajout multiple)" VerticalAlignment="Center"/>
        <CheckBox x:Name="ViewModel" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" Margin="5,0,0,0" Content="Inclure les ViewModels" VerticalAlignment="Center"/>
 
        <Label Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" Name="lblTips" Content="Tips" HorizontalAlignment="Left" Margin="0,0" VerticalAlignment="Bottom" />
        <Label Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="3" Name="lblTips2" Content="Tips" HorizontalAlignment="Left" Margin="0,0" VerticalAlignment="Bottom" />
 
    </Grid>
 
</Window>
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
private void BtnMoreClass_Click(object sender, RoutedEventArgs e)
        {
            i_input++;
 
            TextBox txt = new TextBox
            {
                Name = "textBox1"+ i_input
            };
 
            this.someStackPanel.Children.Add(txt);
            this.someStackPanel.RegisterName(txt.Name, txt);
        }
 
        private void BtnLessClass_Click(object sender, RoutedEventArgs e)
        {
            TextBox txt = (TextBox)this.someStackPanel.FindName("textBox1");
            if (txt != null)
            {
                string message = string.Format("The number is {0}", txt.Text);
 
                MessageBox.Show(message);
            }
            else
            {
                MessageBox.Show("Textbox is null");
            }
        }
J'essai dans une fenêtre, lorsque l'utilisateur clique sur le bouton Ajouter une autre classe, d'ajouter une textbox.
Si il clique plusieurs fois, ça va lui ouvrir autant de textbox qu'il aura cliqué.
Le soucis, c'est que pour une textbox, j'arrive à récupérer sa valeur, mais si il clique genre 2 fois, je ne vois pas comment récupérer chaque textbox.
En JS, les input auraient la même classe, et avec une boucle je peux tout récupérer, mais la je vois pas comment faire.
Si quelqu'un peut m'aider

Merci d'avance !