Joyce de Lanna Joyce de Lanna - 1 year ago 134
C# Question

GestureRecognizer doesn't work only in ios xamarin.forms

I am using xamarin.forms to do an app but,
for some reason, after I change this page, I turned the image bigger and added some grids, the gesturerecognizer stopped work only in iphone, in android it works normally...cam someone see the problem in this code? because, so far, I can't.
I am creating a page programatically because of the template that I need.

private void CriaTela()
{
int row = 0;
int column = 0;

gridtextura.RowSpacing = 5;
gridtextura.ColumnSpacing = 15;

lstCategorias = lstCategorias.OrderBy(o => o.nome).ToList();

foreach (var item in lstCategorias)
{
Grid GridContent = new Grid
{
RowSpacing = 0,
//BackgroundColor = Color.Pink,
VerticalOptions = LayoutOptions.FillAndExpand,
RowDefinitions =
{
new RowDefinition { Height = new GridLength(8, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }
}
};

var textura = new CachedImage();
textura.Source = "texturaCateg";
textura.HorizontalOptions = LayoutOptions.FillAndExpand;
textura.VerticalOptions = LayoutOptions.FillAndExpand;
textura.Aspect = Aspect.Fill;

GridContent.BindingContext = item;

Grid boxColorView = new Grid
{
RowSpacing = 0,
// BackgroundColor = Color.Pink,
VerticalOptions = LayoutOptions.FillAndExpand,
RowDefinitions =
{
new RowDefinition { Height = new GridLength(2, GridUnitType.Star) },
new RowDefinition { Height = new GridLength(8, GridUnitType.Star) }
}
};

boxColorView.Children.Add(new BoxView { Color = Color.FromHex(item.corFundo), VerticalOptions = LayoutOptions.FillAndExpand }, 0, 1 );
boxColorView.Children.Add(textura, 0, 1);

boxColorView.Children.Add(new BoxView { VerticalOptions = LayoutOptions.FillAndExpand }, 0, 0);
gridtextura.Children.Add(boxColorView, column, row);
gridtextura.Children.Add(GridContent, column, row);

//Qual categoria foi escolhida?
var CliqueCategoria = new TapGestureRecognizer();

CliqueCategoria.Tapped += (s, e) =>
{
CriaLoading();
var stacklayout = s as Grid;
categoriaEscolhida = (Categorias)stacklayout.BindingContext;
ChamaProdutos();
};

GridContent.GestureRecognizers.Add(CliqueCategoria);
GridContent.BackgroundColor = Color.Green;
if (item.imagem != null && item.imagem != "")
{
int initIndex = item.imagem.IndexOf(',');
string image = "";

image = item.imagem.Substring(initIndex + 1);

try
{
GridContent.Children.Add(new CachedImage { Source = ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String(image))), VerticalOptions = LayoutOptions.FillAndExpand }, 0, 0);
}
catch (Exception e)
{
GridContent.Children.Add(new CachedImage { Source = "error.png", VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.Fill, HeightRequest = 50, WidthRequest = 50 }, 0, 0);

}
}

GridContent.Children.Add(new Label { Text = item.nome, TextColor = Color.FromHex(item.corTexto), FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)), FontAttributes = FontAttributes.Bold, HorizontalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.CenterAndExpand }, 0, 1 );

if (column == 0)
{
column = 1;
}
else
{
column = 0;
row++;
}

}

}


---------------- edit-------------------

I know a bit more about this problemm...because now I have a image that is a button...and it was working...but now, it is over other image and then it doesnt work anymore...but it's over the other image...it's the same case of this code I posted here...I have a grid over other..at the same position and width and length...and the top grid doesnt receive the tap

Answer Source

The problem was in xaml...The main grid was inside other grid...this other grid was creating the problem...I think maybe it was over the clicks

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download