tap在ios xamarin.forms中不起作用

时间:2017-09-28 01:54:50

标签: visual-studio xaml mobile layout xamarin.forms

我有2个网格:一个重叠另一个...在我的android项目中它运行良好但在我的ios设备中,tapgesturerecognizer不起作用。水龙头位于顶部网格中。 我尝试在网格下输入透明并将其中一个放入ContentView(有人告诉它可以作为答案,但不幸的是,它不是)......但似乎没有任何工作......我很绝望...... 2天搜索它,这是一个工作问题,我想我会因此而遇到问题 如果可以的话,请尽量帮助我。 它只是另一个网格的第0行和第0列中的两个网格...... 日志中没有错误...但是点击不会到达它应该到达的功能。

代码

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,
                Margin = new Thickness(0, 5, 0, 0),
                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,
                //InputTransparent = true,
                VerticalOptions = LayoutOptions.FillAndExpand,
                RowDefinitions =
            {
                new RowDefinition { Height = new GridLength(2, GridUnitType.Star) },
                new RowDefinition { Height = new GridLength(8, GridUnitType.Star) }
            }
            };

            boxColorView.Children.Add(new StackLayout { BackgroundColor = 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.NumberOfTapsRequired = 1;
            CliqueCategoria.Tapped += (s, e) =>
            {
                CriaLoading();
                var stacklayout = s as Grid;
                categoriaEscolhida = (Categorias)stacklayout.BindingContext;
                ChamaProdutos();
            };

            GridContent.GestureRecognizers.Add(CliqueCategoria);

            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++;
            }

        }

    }

0 个答案:

没有答案