Bonjour,
j'e rencontre à problème, je n'arrive pas à effacer ma grille.
Je m'explique, j'ai créer une grille avec des boutons placer dedans, chaque bouton correspond à un champ différent quand on clique sur un des boutons une popup apparaît dans laquelle il est possible de renseigner un chiffre ce chiffre, pour le moment j'ai répartit mon code en plusieurs partie un fichier appelé "AssesmentGridPage.xaml" dans la qu’elle il y a ma vue et un fichier "AssesmentGridPageModel.cs" qui s'occupe des actions de ma vue et enfin un fichier "PopupAssementGridPage.xaml" dans laquelle j'ai créer une popup.
Quand j’appelle ma view (AssesmentGridPage), elle créer la grille avec les boutons dedans. quand je clique sur un des boutons la popup du fichier "PopupAssementGridPage" apparaît je renseigne une valeur. cette valeur est envoyé dans la méthode "FindGridCollectionValue" qui est dans le fichier "AssesmentGridPageModel.cs", cette méthode s'occupe d'attribuer la valeur de chaque bouton dans une ObservableCollection puis ma méthode appel le constructeur AssesmentGridPage qui attent en paramètre une ObservableCollection, je lui envoie donc l' ObservableCollection avec la valeur de mes boutons. Dans ce constructeur je récréer une grille avec les nouvelles valeurs de boutons, j'ai vérifier et mon code fonctionne correctement.
La seule chose que je n'arrive pas à faire c'est faire en sorte que la grille s'actualise au début je pensait supprimer l'ancienne grille puis afficher la nouvelle avec les bonnes valeur mais je n'est pas réussit.
Auriez vous une idée ou solution à me soustraite ?
Je vais à présent vous mettre à disposition mes trois fichier, si vous avez des questions sur mon code ou des suggestion d’amélioration n'hésitez pas à m'en faire part je suis encore débutant dans la développent et a programmation) :
le fichier AssesmentGridPage.xaml :
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 <?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="PolQual.Views.AssesmentGridPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:viewModels="clr-namespace:PolQual.ViewModels" Title=""> <ContentPage.BindingContext> <viewModels:AssesmentGridPageModel /> </ContentPage.BindingContext> <ContentPage.Content> <StackLayout> <Label FontSize="25" HeightRequest="70" HorizontalOptions="Center" Text="Rue d'alloville " /> <ScrollView> <Grid x:Name="gridLayout" Margin="5" HorizontalOptions="Center" VerticalOptions="Start" /> </ScrollView> <Editor BackgroundColor="WhiteSmoke" HeightRequest="245" HorizontalOptions="Center" IsSpellCheckEnabled="True" Keyboard="Text" Placeholder="Ecrivez votre commentaire !" VerticalOptions="Center" WidthRequest="552" /> <Grid x:Name="gridLayout2" BackgroundColor="#EDEDF0" HorizontalOptions="EndAndExpand" VerticalOptions="End"> <Grid.RowDefinitions> <RowDefinition Height="100" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*" /> </Grid.ColumnDefinitions> <Button Grid.Row="0" Grid.Column="0" Text="Précédent" TextColor="Black" /> <Button Grid.Row="0" Grid.Column="4" Text="Suivant" TextColor="Black" /> <Button Grid.Row="0" Grid.Column="1" Clicked="ShowPopupHelpPage" Text="Aide" TextColor="Black" /> <Label Grid.Row="0" Grid.Column="2" FontSize="50" HorizontalOptions="Center" Text="1/x" TextColor="Black" VerticalOptions="Center" /> </Grid> </StackLayout> </ContentPage.Content> </ContentPage>
le behind :
Code cs : 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
109
110
111
112
113
114
115 using System; using System.Collections.Generic; using System.Threading; using System.Linq; using System.Text; using System.Threading.Tasks; using Xamarin.Forms; using Xamarin.Forms.Xaml; using PolQual.ViewModels; using Rg.Plugins.Popup.Services; using System.Collections.ObjectModel; namespace PolQual.Views { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class AssesmentGridPage : ContentPage { private AssesmentGridPageModel _agpm; private Button _gridButton; public AssesmentGridPageModel AGPM { get => _agpm; } public Button GridButton { get => _gridButton; set => _gridButton = value; } public AssesmentGridPage() { _agpm = new AssesmentGridPageModel(); InitializeComponent(); BindingContext = _agpm; _agpm.NewGridCollectionValue(); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = 183 }); gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = 183 }); gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = 183 }); int ProductIndex = 0; for (int rowIndex = 0; rowIndex < 6; rowIndex++) { for (int columnIndex = 0; columnIndex < 3; columnIndex++) { if (ProductIndex >= _agpm.GridCollection.Count) { return; } var grid = _agpm.GridCollection[ProductIndex]; GridButton = new Button { ClassId = "" + ProductIndex, Text = grid.Name + "\r\n" + grid.Value, BackgroundColor = Color.FromHex(grid.Color), }; int request = grid.Value; GridButton.Clicked += async (object o, EventArgs e) => await PopupNavigation.Instance.PushAsync(new PopupAssementGridPage(request, Convert.ToInt32(ClassId))); gridLayout.Children.Add(GridButton, columnIndex, rowIndex); ProductIndex += 1; } } } public AssesmentGridPage(ObservableCollection<ViewModels.Grid> UpdateList) { InitializeComponent(); BindingContext = _agpm; gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.RowDefinitions.Add(new RowDefinition { Height = 70 }); gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = 183 }); gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = 183 }); gridLayout.ColumnDefinitions.Add(new ColumnDefinition { Width = 183 }); int ProductIndex = 0; for (int rowIndex = 0; rowIndex < 6; rowIndex++) { for (int columnIndex = 0; columnIndex < 3; columnIndex++) { if (ProductIndex >= UpdateList.Count) { return; } var grid = UpdateList[ProductIndex]; GridButton = new Button { ClassId = "" + ProductIndex, Text = grid.Name + "\r\n" + grid.Value, BackgroundColor = Color.FromHex(grid.Color), }; int request = grid.Value; GridButton.Clicked += async (object o, EventArgs e) => await PopupNavigation.Instance.PushAsync(new PopupAssementGridPage(request, Convert.ToInt32(ClassId))); gridLayout.Children.Add(GridButton, columnIndex, rowIndex); ProductIndex += 1; } } } private async void ShowPopupHelpPage(object o, EventArgs e) { await PopupNavigation.Instance.PushAsync(new PopupHelpPage()); } } }
AssesmentGridPageModel.cs :
Code cs : 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 using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using PolQual.Views; using System.Collections.ObjectModel; namespace PolQual.ViewModels { public class AssesmentGridPageModel : INotifyPropertyChanged { private List<Grid> _gridCollection; private static ObservableCollection<Grid> _gridCollectionValue; private AssesmentGridPage _agp; public List<Grid> GridCollection { get => _gridCollection; set => _gridCollection = value; } public static ObservableCollection<Grid> GridCollectionValue { get => _gridCollectionValue; set => _gridCollectionValue = value; } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged([CallerMemberName] string propertyname = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname)); } //public AssesmentGridPageModel() //{ //} public void NewGridCollectionValue() { GridCollection = GetGrid(); GridCollectionValue = new ObservableCollection<Grid>(); for (int search = 0; search < GridCollection.Count(); search++) { GridCollectionValue.Add(new Grid() { Key = GridCollection[search].Key, Name = GridCollection[search].Name, Value = GridCollection[search].Value, Color = GridCollection[search].Color }); } } public void FindGridCollectionValue(int ButtonValue, int ButtonIndex) { for (int search = 0; search < ButtonIndex+1; search++) { int essai = GridCollectionValue[ButtonIndex].Value = ButtonValue; GridCollectionValue[ButtonIndex].Value = ButtonValue; } _agp = new AssesmentGridPage(GridCollectionValue); } public List<Grid> GetGrid() { List<Grid> Grids = new List<Grid> { new Grid { Key = 0, Name = "Petit déchet", Value = 0, Color = "0078ae" }, new Grid { Key = 1, Name = "Déchet critique", Value = 0, Color = "0078ae" }, new Grid { Key = 2, Name = "Déjection canine", Value = 0, Color = "0078ae" }, new Grid { Key = 3, Name = "Encombrant", Value = 0, Color = "3cc194" }, new Grid { Key = 4, Name = "Dépôt sauvage", Value = 0, Color = "3cc194" }, new Grid { Key = 5, Name = "Carton", Value = 0, Color = "3cc194" }, new Grid { Key = 6, Name = "Bac à demeure", Value = 0, Color = "3cc194" }, new Grid { Key = 7, Name = "Petit déchet", Value = 0, Color = "fad744" }, new Grid { Key = 8, Name = "Déchet critique", Value = 0, Color = "fad744" }, new Grid { Key = 9, Name = "Avaloirs", Value = 0, Color = "fad744" }, new Grid { Key = 10, Name = "Corbeilles", Value = 0, Color = "6f2e2e" }, new Grid { Key = 11, Name = "Herbe", Value = 0, Color = "a43122" }, new Grid { Key = 12, Name = "Feuille", Value = 0, Color = "a43122" }, new Grid { Key = 13, Name = "Mobilier", Value = 0, Color = "ffe5ec" }, new Grid { Key = 14, Name = "Graffiti", Value = 0, Color = "c9c9d4" }, new Grid { Key = 15, Name = "Affichage", Value = 0, Color = "783e71" }, new Grid { Key = 16, Name = "Auto", Value = 0, Color = "783e71" }, new Grid { Key = 17, Name = "Note", Value = 0, Color = "fe9004" } }; return Grids; } } public class Grid { private int _key; public int Key { get => _key; set => _key = value; } private string _name; public string Name { get => _name; set => _name = value; } private int _value; public int Value { get => _value; set => _value = value; } private string _color; public string Color { get => _color; set => _color = value; } } }
PopupAssementGridPage.xaml :
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 <?xml version="1.0" encoding="utf-8" ?> <Pages:PopupPage x:Class="PolQual.Views.PopupAssementGridPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:Pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"> <StackLayout Margin="5" Padding="5" BackgroundColor="White" HeightRequest="300" HorizontalOptions="Center" VerticalOptions="Center" WidthRequest="600"> <StackLayout> <Grid> <Grid.RowDefinitions> <RowDefinition Height="30*" /> <RowDefinition Height="10*" /> <RowDefinition Height="20*" /> <RowDefinition Height="10*" /> <RowDefinition Height="30*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="25*" /> <ColumnDefinition Width="50*" /> <ColumnDefinition Width="25*" /> </Grid.ColumnDefinitions> <Label Grid.Row="0" Grid.Column="1" FontSize="25" HorizontalOptions="Center" HorizontalTextAlignment="Center" Text="Nombre de petit déchet au point de comptage :" VerticalTextAlignment="Center" /> <Entry x:Name="EntryValue" Grid.Row="2" Grid.Column="1" Keyboard="Numeric" Placeholder="Veuillez saisir la valeur" /> <Button Grid.Row="4" Grid.Column="0" Clicked="ReturnToOldPage" Text="Annuler" /> <Button Grid.Row="4" Grid.Column="2" Clicked="ValidateValue" Text="Valider" /> </Grid> </StackLayout> </StackLayout> </Pages:PopupPage>
code behind :
Code cs : 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 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using PolQual.ViewModels; using Xamarin.Forms; using Xamarin.Forms.Xaml; using Rg.Plugins.Popup.Services; using System.Text.RegularExpressions; namespace PolQual.Views { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class PopupAssementGridPage { private AssesmentGridPageModel _agpm; private int indexButton; public static bool essai; public AssesmentGridPageModel AGPM { get => _agpm; } //constructeur public PopupAssementGridPage(int request, int index) { _agpm = new AssesmentGridPageModel(); essai = true; indexButton = index; InitializeComponent(); EntryValue.Placeholder = Convert.ToString(request); } //bouton d'annulation private void ReturnToOldPage(object sender, EventArgs e) { PopupNavigation.Instance.PopAsync(true); } //bouton de validation private void ValidateValue(object sender, EventArgs e) { int value = Convert.ToInt32(EntryValue.Text); _agpm.FindGridCollectionValue(value, indexButton); PopupNavigation.Instance.PopAsync(true); } } }
Partager