Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Navigation.PushAsync not working clickable stacklayout

$
0
0

Hello I am very new to Xamarin I tried to make a clickable stackLayout that that is reusable and with a click event that it takes to another navigation page but it is not working here is my code:

XML
<?xml version="1.0" encoding="UTF-8"?> <StackLayout xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Pruebas_.carrito.View.vistaProducto.itemViewProducto"> <StackLayout x:Name="item" Orientation="Horizontal" HorizontalOptions="FillAndExpand" > <Image Source="remera.jpg" x:Name="displayImage" HeightRequest="80" WidthRequest="80"/> <StackLayout Orientation="Vertical" Padding="1"> <Label Text="{Binding Nombre}" x:Name="displayName" FontSize="Small"/> <Label Text="{Binding Descripcion}" x:Name="displayDescription" FontSize="Micro"/> <Label Text="{Binding Precio}" x:Name="displayPrice" FontSize="Small"/> <StackLayout Orientation="Horizontal"> <Button Image="carrito2.png" x:Name ="btnagregar" Command="{Binding cmd_agregar}"/> <Button x:Name="btnVer" Text="VER" ClassId="{Binding ID}" Clicked="btnVer_Clicked"/> </StackLayout> </StackLayout> </StackLayout> </StackLayout>

C#
`
namespace Pruebas_.carrito.View.vistaProducto
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class itemViewProducto : StackLayout
{
public itemViewProducto ()
{
//InitializeComponent ();
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += stackTapped;
//item.GestureRecognizers.Add(tapGestureRecognizer);
}

    private void stackTapped(object sender, EventArgs e){


        StackLayout stack = sender as StackLayout;

        Label nombre = stack.FindByName<Label>("displayName");
        Label descripcion = stack.FindByName<Label>("displayDescription");
        Label precio = stack.FindByName<Label>("displayPrice");
        Image imagen = stack.FindByName<Image>("displayImage");

        Debug.WriteLine("Nombre:"+nombre.Text+" Descripcion: "+descripcion.Text+" Precio: "+precio.Text+" Imagen: "+imagen.Source.ToString());
        abrirVentana();
    }

    private void abrirVentana()
    {
        Navigation.PushAsync(new CarritoView());
    }

    private void btnVer_Clicked(object sender, EventArgs e)
    {
        Navigation.PushAsync(new FichaProducto());
    }
    }
}

`

How I insert this stack into another contentView:
`

    </common:itemViewProducto>

`

PS: I tried to format my code here but it doesnt work


Viewing all articles
Browse latest Browse all 89864


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>