I'm trying to make an app in xamarin and till now, after some hour video and many forums I have always find a solution, But this time I'm not able to give it away.
I have a Listview of a list of my own class "Cliente" private List<Cliente> clienti;
I have bind the object to the listview to show data and I have put the ItemTapped
<ListView ItemsSource="{Binding Clienti}" HasUnevenRows="True" ItemTapped="TapCliente">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="0,0,0,5">
<Frame BorderColor="Black">
<StackLayout Orientation="Vertical">
<Label Text="{Binding rag_sociale}"/>
<Label Text="{Binding ind_anag }"/>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding cap_anag }" HorizontalOptions="Start"/>
<Label Text="{Binding loc_anag }" HorizontalOptions="End"/>
<Label Text="{Binding prov_anag }" HorizontalOptions="End"/>
</StackLayout>
</StackLayout>
</Frame>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Now I would like to open a new page when I tap a row of the list view passing a value of that row to use it in the new page, so I have write:
public void TapCliente(object sender, ItemTappedEventArgs e)
{
Cliente cliente_selezionato = (Cliente)
((ListView)sender).SelectedItem;
Navigation.PushModalAsync(new SchedaAnagraficaPage(cliente_selezionato.cod_anag));
}
The "cod_anag" is an int value, but on the constructor of the new page, I can't set the parameter to receive, If I write:
public SchedaAnagraficaPage(int codice_cliente)
{
InitializeComponent();
}
It write "Can't Convert form views.SchedaAnagraficaPage to Xamarin.Forms.Page"
If I write:
public SchedaAnagraficaPage(Cliente cliente)
{
InitializeComponent();
}
It write "Can't convert from int to models.Cliente"
Any Suggestion? Thanks
First , you can check with navigating without paramater whether it works :
Navigation.PushModalAsync(new SchedaAnagraficaPage());
Then can add int
argument to navigate .
Can't Convert form views.SchedaAnagraficaPage to Xamarin.Forms.Page
Occurs this error , need to check the SchedaAnagraficaPage whether inherit from ContentPage :
public partial class SchedaAnagraficaPage : ContentPage
{
public SchedaAnagraficaPage(int codice_cliente)
{
InitializeComponent();
}
}
In addition ,if write SchedaAnagraficaPage
method as follow:
public SchedaAnagraficaPage(Cliente cliente)
{
InitializeComponent();
}
The TapCliente
method should be as follow :
public void TapCliente(object sender, ItemTappedEventArgs e)
{
Cliente cliente_selezionato = (Cliente)((ListView)sender).SelectedItem;
Navigation.PushModalAsync(new SchedaAnagraficaPage(cliente_selezionato));
}