Bonjour,
j'essaie désespérément de lier mon formulaire à une classe que j'ai conçu.
mais je ne sais pas comment m'y prendre.
voici ma classe.
Code C# : 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Verification_Lotto { class Joueur { private string nom; private numeroLotto num1, num2, num3, num4, num5, num6; public Joueur(string p_nom, int p_num1, int p_num2, int p_num3, int p_num4, int p_num5, int p_num6) { nom = p_nom; num1.Numero = p_num1; num2.Numero = p_num2; num3.Numero = p_num3; num4.Numero = p_num4; num5.Numero = p_num5; num6.Numero = p_num6; } public Joueur() { nom = ""; num1.Numero = num2.Numero = num3.Numero = num4.Numero = num5.Numero = num6.Numero = 0; } public string Nom { set { nom = value; } get { return nom; } } public numeroLotto Num1 { set { num1 = value; } get { return num1; } } public numeroLotto Num2 { set { num2 = value; } get { return num2; } } public numeroLotto Num3 { set { num3 = value; } get { return num3; } } public numeroLotto Num4 { set { num4 = value; } get { return num4; } } public numeroLotto Num5 { set { num5 = value; } get { return num5; } } public numeroLotto Num6 { set { num6 = value; } get { return num6; } } } }
la classe numeroLotto ( à mon avis pas utile au binding )
Code C# : 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 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Verification_Lotto { class numeroLotto { int numero; bool tire; public numeroLotto(int p_numero, bool p_tire) { numero = p_numero; tire = p_tire; } public numeroLotto() { numero = 0; tire = false; } public int Numero { set { numero = value; } get { return numero; } } public bool Tire { set { tire = value; } get { return tire; } } } }
et voici le code XAML du formulaire auquel je veux binder ma classe.
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
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 <Window x:Class="Verification_Lotto.AjoutJoueur" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:my="clr-namespace:Verification_Lotto" Title="Ajout d'un nouveau joueur" Height="340" Width="800" Loaded="Window_Loaded"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="40"/> <RowDefinition Height="30"/> <RowDefinition Height="30"/> <RowDefinition Height="30"/> <RowDefinition Height="30"/> <RowDefinition Height="30"/> <RowDefinition Height="30"/> <RowDefinition Height="30"/> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="50"/> <ColumnDefinition Width="100"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Label Grid.Column="1" Grid.Row="1" VerticalAlignment="Center">Nom :</Label> <Label Grid.Column="1" Grid.Row="2" VerticalAlignment="Center">Numéro 1 :</Label> <Label Grid.Column="1" Grid.Row="3" VerticalAlignment="Center">Numéro 2 :</Label> <Label Grid.Column="1" Grid.Row="4" VerticalAlignment="Center">Numéro 3 :</Label> <Label Grid.Column="1" Grid.Row="5" VerticalAlignment="Center">Numéro 4 :</Label> <Label Grid.Column="1" Grid.Row="6" VerticalAlignment="Center">Numéro 5 :</Label> <Label Grid.Column="1" Grid.Row="7" VerticalAlignment="Center">Numéro 6 :</Label> <Grid Grid.Column="1" Grid.Row="8" Grid.ColumnSpan="2" > <Grid.ColumnDefinitions> <ColumnDefinition Width="150"/> <ColumnDefinition/> <ColumnDefinition/> <ColumnDefinition Width="150"/> </Grid.ColumnDefinitions> <Button Name="btAjouter" Grid.Column="1" Grid.Row="0" Content="Valider" Height="30" Width="150" Click="btAjouter_Click"></Button> <Button Name="btAnnuler" Grid.Column="2" Grid.Row="1" Content="Annuler" Height="30" Width="150" Click="btAnnuler_Click"></Button> </Grid> <TextBox Grid.Column="2" Grid.Row="1" Name="tbNom" Height="26" Width="280" HorizontalAlignment="Left" VerticalAlignment="Center"></TextBox> <StackPanel Grid.Column="2" Grid.Row="2" Orientation="Horizontal"> <my:NumericUpDown x:Name="NudNum1" Valeur="1"></my:NumericUpDown> </StackPanel> <StackPanel Grid.Column="2" Grid.Row="3" Orientation="Horizontal"> <my:NumericUpDown x:Name="NudNum2" Valeur="1" ></my:NumericUpDown> </StackPanel> <StackPanel Grid.Column="2" Grid.Row="4" Orientation="Horizontal"> <my:NumericUpDown x:Name="NudNum3" Valeur="1" ></my:NumericUpDown> </StackPanel> <StackPanel Grid.Column="2" Grid.Row="5" Orientation="Horizontal"> <my:NumericUpDown x:Name="NudNum4" Valeur="1" ></my:NumericUpDown> </StackPanel> <StackPanel Grid.Column="2" Grid.Row="6" Orientation="Horizontal"> <my:NumericUpDown x:Name="NudNum5" Valeur="1" ></my:NumericUpDown> </StackPanel> <StackPanel Grid.Column="2" Grid.Row="7" Orientation="Horizontal"> <my:NumericUpDown x:Name="NudNum6" Valeur="1" ></my:NumericUpDown> </StackPanel> </Grid> </Window>
je veux donc lier ma textbox "tbnom.text" à Joueur.Nom, NUD1.Valeur à Joueur.numeroLotto.Numero, etc...
Un grand merci.
Partager