Acceptance Criteria
TextBox starts empty each time the application runs.ShoppingList.txt.TextBox.Continue your completed 0.3 First Day application. Add a school shopping list, observe what happens when the application closes, and then add buttons to save and load the text.
Goal: Explain the difference between text in a running application and text saved in a file. Saving writes the current text to ShoppingList.txt. Loading reads that saved text back into the shopping-list TextBox.
Name the backup First Day 0.3 Backup LastName.
Keep the working folder and solution names unchanged. Continue working in the original folder, keeping the backup as your completed 0.3 checkpoint.
Fix any existing errors before continuing.
TextBoxFirstDayScenario/MainWindow.xamlKeep the Window height at 800 and width at 430. The existing Grid has six row definitions and one column definition. Keep those definitions and the existing 0.3 controls in place.
Find the outer Weather StackPanel, which contains the Weather heading and the horizontal row with the rain checkbox and clothing button. Locate that outer panel's closing tag. Immediately after it and before the existing output TextBox, insert this entire block as a direct child of the Grid.
<StackPanel Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Top"> <TextBlock Text="School shopping list" FontWeight="Bold" Margin="5,10,0,0" /> <TextBox x:Name="shoppingListTextBox" Height="90" Margin="5" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" /> </StackPanel>

The new panel uses Grid row 3. Its heading appears above the shopping-list text box. The text box accepts multiple lines, wraps long lines, and shows a vertical scrollbar when needed. Leave its initial text empty.
Text disappears after closingTextBoxEnter one item per line.
TextBox is emptyThe text existed in the running application. You have not added a way to save it, so it disappears when the application closes.
Save shopping list buttonIn MainWindow.xaml, find the new shopping-list text box. Immediately after its line, before the shopping-list panel's closing tag, insert this entire block. The inner StackPanel arranges the Save button and the Load button you will add later from left to right.
<StackPanel Orientation="Horizontal"> <Button x:Name="saveShoppingListButton" Width="125" Content="Save shopping list" Margin="5" /> </StackPanel>

Save shopping list in the XAML designerVisual Studio creates a Click event handler and opens MainWindow.xaml.cs.
Find the generated saveShoppingListButton_Click method. Paste only these two statements between its opening and closing braces.
File.WriteAllText("ShoppingList.txt", this.shoppingListTextBox.Text);
this.textOutput.Text = "Shopping list saved.";The designer adds the XAML
Click
attribute automatically. For this button it must be
Click="saveShoppingListButton_Click"
. Its value must exactly match the generated method name, including capitalization.
System.IO using statementAdd this line with the other using statements at the top of MainWindow.xaml.cs if it is not already present.
using System.IO;Click Save shopping list and verify the confirmationThe output area should say Shopping list saved..
ShoppingList.txt in your working solution folderUse File Explorer to search for ShoppingList.txt. With the usual Visual Studio run settings, it is under the project's bin output folder, possibly inside configuration or framework subfolders.
The file still contains the text after the application closes. This is persistent storage.
TextBox still starts emptyTextBox is emptySaving writes to the file; it does not read the file back into the TextBox. You will add loading in Step 4. Leave the application running for the next check.
Enter one item per line.
ShoppingList.txt and verify it still contains Notebook and PensOpen the file from the same location. Changing the TextBox changes the running application's text. The saved file stays the same until you click Save.
Click Save shopping listNotebook and Pens should no longer be present. Each call to File.WriteAllText replaces the file's contents with the current shopping-list text.
Load shopping list buttonIn MainWindow.xaml, find the Save button inside the inner horizontal StackPanel. Insert this line immediately after the Save button and before that inner panel's closing tag.
<Button x:Name="loadShoppingListButton" Width="125" Content="Load shopping list" Margin="5" />

The shopping-list panel now contains the heading, text box, and inner button row, in that order. Both buttons belong inside the inner horizontal StackPanel.
Load shopping list in the XAML designerVisual Studio creates the event handler and opens MainWindow.xaml.cs. In XAML, the designer adds the Click attribute with the value loadShoppingListButton_Click.
Paste this code between the opening and closing braces of the generated loadShoppingListButton_Click method.
if (File.Exists("ShoppingList.txt"))
{
this.shoppingListTextBox.Text = File.ReadAllText("ShoppingList.txt");
this.textOutput.Text = "Shopping list loaded.";
}
else
{
this.textOutput.Text = "Save a shopping list before loading.";
}The File.Exists check lets the button display a message if there is no saved file yet. Keep this code inside the Load button's event handler so loading happens when you click the button.
The shopping-list TextBox should begin empty.
Click Load shopping listTextBoxThe output area should say Shopping list loaded..
ShoppingList.txt and compare its contents with the TextBoxThe shopping-list TextBox and the saved file should contain the same text.
TextBox and load againTextBox and delete itClick Load shopping list again without clicking Save firstClearing the TextBox did not change the file. Loading reads the same saved text again. Clicking Save while the TextBox is empty would instead replace the file's contents with empty text.
The TextBox starts empty on each run. Save updates the file; Load restores the saved text.
Verify that LastName.sln and the FirstDayScenario project folder are included.
Resubmit an updated ZIP when needed.