'display selected item from listview with ability to edit them in xamarinform
I'm trying to select item from list view and then open another page and Display full form with ability to Edit this details in Fire base database But i faced this error when running the code :
I wrote the Service which must Edit the object and then
first this is my list code which i have to select from it :
<StackLayout>
<ListView
HasUnevenRows="True"
ItemsSource="{Binding Patients}"
SelectedItem="{Binding SelectedPatient, Mode=TwoWay}"
SelectionMode="Single">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid RowDefinitions="Auto,Auto,Auto">
<Frame
OutlineColor="#5A5A59"
Padding="25"
Margin="0,10,0,0"
CornerRadius="10"
HasShadow="True">
<StackLayout Orientation="Horizontal">
<BoxView
Color="Maroon"
WidthRequest="1"
Margin="5, 0, 10, 0" />
<Label Grid.Row="0" Text="{Binding PatientName}" Font="Small" TextColor="Black" LineBreakMode="TailTruncation" Margin="15"/>
<Label Grid.Row="0" Grid.Column="1" Text="{Binding PatientMobileNO}" Font="Small" TextColor="Black" LineBreakMode="TailTruncation" Margin="15"/>
</StackLayout>
</Frame>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
then in the ListpageModel View i have this code
public Patient SelectedPatient
{
get => _SelectedPatient;
set
{
SetProperty(ref _SelectedPatient, value, nameof(SelectedPatient));
App.Current.MainPage.Navigation.PushAsync(new PatientProfileDetailsPage(value));
}
}
and at last this is my code in PatientProfileDetailsPage c# and in xaml code i just put 2 Entries in order to displayed data on it :
public partial class PatientProfileDetailsPage : ContentPage
{
Patient Patient;
public PatientProfileDetailsPage(Patient cat)
{
InitializeComponent();
Patient = cat;
PatientNameEntry.Text = cat.PatientName;
MobileEntry.Text = cat.PatientMobileNO;
EditPatientClick();
}
public async void EditPatient()
{
PatientService PatientService = new PatientService();
Patient.PatientName = PatientNameEntry.Text;
Patient.PatientMobileNO = MobileEntry.Text; ;
await PatientService.EditPatient(Patient);
await DisplayAlert("Adding", "The Category Edited", "Ok");
await Navigation.PushAsync(new PatientsListPage());
}
void EditPatientClick()
{
save.GestureRecognizers.Add(new TapGestureRecognizer()
{
Command = new Command(() =>
{
EditPatient();
})
});
}
}
There's no error in the code, it's just on i trying to run it it displayed expction page as i attached in the image and this is the error txt :
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
