Приложение закрывается без каких-либо ошибок, это происходит, когда я пытаюсь ввести некоторые данные в поле ввода, я использую SQLite и привязываю ViewModels к представлениям с использованием интерфейса INotifyPropertyChanged в модели.Я не знаю, почему это происходит, если вы не пытаетесь ввести какое-либо значение, которое приложение не закрывает.
Это ViewModel:
class PersonViewModel : PersonModel
{
public ICommand Save { get; private set; }
public ICommand Update { get; private set; }
public ICommand Delete { get; private set; }
public ICommand New { get; private set; }
public PersonViewModel()
{
Save = new Command(() =>
{
PersonModel model = new PersonModel()
{
Name = Name,
Lastname = Lastname,
Country = Country,
Email = Email,
Date = Date,
City = City
};
using (var context = new DataContext()) // Cierra la conexion (Dispose) cuando sale el scope
{
context.Insert(model);
}
});
Update = new Command(() =>
{
PersonModel model = new PersonModel()
{
Name = Name,
Lastname = Lastname,
Country = Country,
Email = Email,
Date = Date,
City = City,
IdPerson = IdPerson
};
using (var context = new DataContext())
{
context.Update(model);
}
});
Delete = new Command(() =>
{
PersonModel model = new PersonModel()
{
Name = Name,
Lastname = Lastname,
Country = Country,
Email = Email,
Date = Date,
City = City,
IdPerson = IdPerson
};
using (var context = new DataContext())
{
context.Delete(model);
}
});
New = new Command(() =>
{
PersonModel model = new PersonModel()
{
Name = string.Empty,
Lastname = string.Empty,
Country = string.Empty,
Email = string.Empty,
Date = DateTime.Now,
City = string.Empty
};
});
}
}
Это View:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ProbandoSqlite.Views.PersonsView">
<ScrollView>
<StackLayout>
<Label Text="Persons" Font="25" TextColor="Green" HorizontalOptions="Center"></Label>
<Entry Placeholder="Name" Text="{Binding Name}"></Entry>
<Entry Placeholder="Lastname" Text="{Binding Lastname}"></Entry>
<Entry Placeholder="Email" Text="{Binding Email}"></Entry>
<Entry Placeholder="Country" Text="{Binding Country}"></Entry>
<Entry Placeholder="City" Text="{Binding City}"></Entry>
<DatePicker Date="{Binding Date}"></DatePicker>
<Button Text="Save" Command="{Binding Save}"></Button>
<Button Text="New" Command="{Binding New}"></Button>
<Button x:Name="btnShow" Text="Show" Clicked="BtnShow_Clicked"></Button>
</StackLayout>
</ScrollView>
</ContentPage>
Это код вида:
public partial class PersonsView : ContentPage
{
public PersonsView ()
{
InitializeComponent ();
this.BindingContext = new PersonViewModel();
}
private void BtnShow_Clicked(object sender, EventArgs e)
{
((NavigationPage)Parent).PushAsync(new ShowView());
}
}