'Saving application data when closed using MVVM pattern
The issue I am having right now is saving data of my applications when I exit. I am using the MVVM pattern to create this application. The application is a simple DataGrid which is bound to a list of Users which are of type TestModel that has a Name, Last Name, Department and an ID.
public ObservableCollection<TestModel> Users { get; set; } = new ObservableCollection<TestModel>();
public MainWindowViewModel()
{
Users.Add(
new TestModel { ID = 1, NAME = "George", LastName = "Williams"});
Users.Add(
new TestModel { ID = 2, NAME = "Bob", LastName = "Smith"});
}
<DataGrid x:Name="MainDataGrid" Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Users}" SelectedItem="{Binding SelectedItem}" AutoGenerateColumns="False" IsReadOnly="True">
<DataGrid.InputBindings>
I implemented another view to add a new User to the list as well as a 3rd view to edit the details about the selected user. Everything works fine.
The issue now is that when I exit my application, all of the Users I created during the session are gone, the data is not saved permanently, only those Users which I created in the MainWindowViewModel constructor remain on launch. How can I save the data permanently so the Users I add during a session are there when I launch again? I am not using a database.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
