You will continue working in the same First Day project you used in 0.2. This week, you will add one button, follow a simple true/false decision, use the debugger to watch the program choose a path, and then connect that decision to an It is raining checkbox.
You do not need previous programming experience. Follow each step in order and use the checkboxes to keep track of where you are.
MainWindow.xaml and MainWindow.xaml.csChoose Clothing button and its horizontal StackPanelname ends in .slnImportant: Do not rename the project files or classes. For this assignment, you are only renaming the outer workspace folder from 0.2 to 0.3.
MainWindow.xaml describes what appears in the window.MainWindow.xaml.cs contains the C# code that runs when the user interacts with the window.FirstDayScenario project if it is collapsedMainWindow.xamlMainWindow.xaml if neededMainWindow.xaml.csnewStudentButton_Click, haveBreakfastButton_Click, and fillBackpackButton_ClickA button handler is a method that runs when a button is clicked. You will add the button in XAML first, then double-click it in the designer so Visual Studio creates the handler for you.
MainWindow.xaml and find the closing tag of the existing StackPanel containing the New student, Have breakfast, and Fill backpack buttons<StackPanel Grid.Row="1"> <TextBlock Text="Weather" FontWeight="Bold" Margin="5,10,0,0" /> </StackPanel>

The new panel belongs directly inside the existing Grid. Its row number places it below the original buttons. The TextBlock displays the bold Weather heading.
MainWindow.xaml<StackPanel Orientation="Horizontal"> <Button x:Name="chooseClothingButton" Content="Choose Clothing" Width="125" Margin="5" /> </StackPanel>

This inner StackPanel will place its controls side by side. It currently contains only the button; later, you will insert the rain checkbox before that button. Keep the inner panel inside the outer Weather panel.
MainWindow.xaml, switch to the visual designer if it is not already visibleChoose Clothing button in the window previewChoose Clothing buttonMainWindow.xaml.cs and create a new click-handler method for that buttonchooseClothingButton_ClickThe new handler should look similar to this:
private void chooseClothingButton_Click(object sender, RoutedEventArgs e)
{
}The button in MainWindow.xaml is now connected to the chooseClothingButton_Click method in MainWindow.xaml.cs. You will add the decision logic inside this method in the next step.
Choose Clothing button appears in the windowMainWindow.xaml.cschooseClothingButton_Click handler you addedprivate void chooseClothingButton_Click(object sender, RoutedEventArgs e)
{
bool isRaining = true;
if (isRaining)
{
this.textOutput.Text = "Wear a rain jacket.";
}
}if (isRaining)Choose Clothing. Visual Studio should pause on the breakpointisRaining. Confirm that its value is trueWhat happened? Because isRaining was true, the statements inside the if block ran.
falseMainWindow.xaml.cs, change only bool isRaining = true; to bool isRaining = false;if (isRaining)Choose ClothingisRaining and confirm that it is now falseThis is an important result: an if block runs only when its condition is true. Right now there is no instruction telling the program what to do when the condition is false.
MainWindow.xaml.cs and find the chooseClothingButton_Click handlerbool isRaining = false; for the first testelse
{
this.textOutput.Text = "Wear a hoodie.";
}Your complete handler should now look like this:
private void chooseClothingButton_Click(object sender, RoutedEventArgs e)
{
bool isRaining = false;
if (isRaining)
{
this.textOutput.Text = "Wear a rain jacket.";
}
else
{
this.textOutput.Text = "Wear a hoodie.";
}
}if (isRaining)Choose ClothingisRaining is falsebool isRaining = false; back to bool isRaining = true;Choose Clothing, and stop at the same breakpointWhat to notice: The same if/else can follow either path. The value of the condition determines which path runs.
MainWindow.xamlMainWindow.xamlChoose Clothing button inside the horizontal StackPanel you added earlier<CheckBox x:Name="rainCheckBox" Content="It is raining" Width="125" Margin="5" HorizontalAlignment="Left" />

The checkbox is named rainCheckBox. C# will use that exact name to check whether the box is selected.
Both controls must be inside the inner horizontal StackPanel. The TextBlock and inner StackPanel must both be inside the outer Weather StackPanel.
MainWindow.xaml.csbool isRaining = true; inside chooseClothingButton_Clickbool isRaining = this.rainCheckBox.IsChecked == true;Your finished handler should now be:
private void chooseClothingButton_Click(object sender, RoutedEventArgs e)
{
bool isRaining = this.rainCheckBox.IsChecked == true;
if (isRaining)
{
this.textOutput.Text = "Wear a rain jacket.";
}
else
{
this.textOutput.Text = "Wear a hoodie.";
}
}if (isRaining)Choose ClothingisRaining. It should be falseChoose ClothingisRaining. It should be trueFinal flow: checkbox state → isRaining → if/else → clothing message
FirstDayScenario project folderYou're finished when your 0.3 workspace has been submitted successfully to FBS.