Hello everyone,
I'm creating a grid in xamarin form in which I'm implementing buttons using a list values that a I want to change throught a popup ( using Rg.Plugins.Popup.Services) that open when I'm Clicking on any of those buttons.
The problem is that, the list in which i'm storing my buttons values (FindGridCollectionValue) is updating correctly, but the values displayed on my buttons doesn't change when I'm validating the value on my Popup.
Here is my code (the view)
-The gird implementation:
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;
}
}
}
and my pop up page code :
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);
}
}
}
and my methods in the view model code :
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);
}
finally, the method which is supposed to reload my grid :
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;
}
}
}