Hi xamarin forum
is it possible to tap an Item in a listView then upon tapping on an item it will go to another page which contains more Details about that item below is my XAML and codebehind for listView
In this code I was able to make use of searchbar to filter what I want to dial or make a call.. but what I want is to add something like 'more info' where I can tap that more info then it will display another page containing more information about the item I tapped/selected so for more clarification if I tapped on 'more info' on Rob's row it will display Rob's Email address Contact numbers Address etc is this possible on my code?
XAML
<StackLayout>
<SearchBar HeightRequest="50" TextChanged="SearchBar_textChanged"></SearchBar>
<ListView x:Name="Contacts">
<ListView.Header>
<Grid ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="Name" Grid.Row="0" Grid.Column="0" HorizontalOptions="CenterAndExpand" />
<Label Text="Company" Grid.Row="0" Grid.Column="1" HorizontalOptions="CenterAndExpand"/>
<Label Text="Phone" Grid.Row="0" Grid.Column="2" HorizontalOptions="CenterAndExpand" />
</Grid>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Label Text="{Binding CustomerName}" Margin="40,10,20,0"/>
<Label Text="{Binding Address}" Margin="40,10,20,0"/>
<Label Text="{Binding Phone}" Margin="15,10,20,0"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
And This is my code behind
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using Xamarin.Forms;
public partial class Contactpage : ContentPage
{
public List<User> tempdata;
public Contactpage()
{
InitializeComponent ();
BindCustomerRecords();
Contacts.ItemsSource = tempdata;
}
private void BindCustomerRecords()
{
tempdata = new List<User>
{
new User(){CustomerName = "Kyle", Address= "Abc St. 123456uj", Phone="111111" },
new User(){CustomerName = "Rob", Address= "Abdw St. f30054", Phone="12345675" },
new User(){CustomerName = "Martin", Address= "Aqw St. 12345q2j", Phone="556795" },
new User(){CustomerName = "Mike", Address= "Abc St. 123456uj", Phone="235465" }
};
}
private void SearchBar_textChanged(object sender, TextChangedEventArgs e)
{
Contacts.BeginRefresh();
if (string.IsNullOrEmpty(e.NewTextValue))
{
Contacts.ItemsSource = tempdata;
}
else
{
Contacts.ItemsSource = tempdata.Where(x => x.CustomerName.StartsWith(e.NewTextValue));
}
Contacts.EndRefresh();
}
}
void SelectedNumber(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
{
var SelectedContact = ((ListView)sender).SelectedItem as User;
if (SelectedContact == null)
return;
var phoneDial = Plugin.Messaging.CrossMessaging.Current.PhoneDialer;
if (phoneDial.CanMakePhoneCall)
phoneDial.MakePhoneCall(SelectedContact.Phone);
}