Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Adjust the code to display paragraphs class BlackCatPage : ContentPage { public

ID: 3801273 • Letter: A

Question

Adjust the code to display paragraphs

class BlackCatPage : ContentPage { public BlackCatPage() { StackLayout mainStack = new StackLayout();

StackLayout textStack = new StackLayout { Padding = new Thickness(5), Spacing = 10 };

// Get access to the text resource. Assembly assembly = GetType().GetTypeInfo().Assembly;

string resource = "BlackCat.Texts.TheBlackCat.txt";

using (Stream stream = assembly.GetManifestResourceStream (resource)) { using (StreamReader reader = new StreamReader (stream)) { bool gotTitle = false; string line;

// Read in a line (which is actually a paragraph)while (null != (line = reader.ReadLine())) { Label label = new Label { Text = line, // Black text for ebooks! TextColor = Color.Black };

if (!gotTitle) { // Add first label (the title) to mainStack. label.HorizontalOptions = LayoutOptions.Center; label.FontSize = Device.GetNamedSize(NamedSize.Medium, label);

label.FontAttributes = FontAttributes.Bold; mainStack.Children.Add(label); gotTitle = true;

} else { // Add subsequent labels to textStack. textStack.Children.Add(label);

}

}

} }

// Put the textStack in a ScrollView with FillAndExpand. ScrollView scrollView = new ScrollView { Content = textStack, VerticalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(5, 0), };

// Add the ScrollView as a second child of mainStack. mainStack.Children.Add(scrollView);

// Set page content to mainStack. Content = mainStack; // White background for ebooks! BackgroundColor = Color.White; // Add some iOS padding for the page. Padding = new Thickness (0, Device.OnPlatform (20, 0, 0), 0, 0);

}

}

Explanation / Answer

class BlackCatPage
{
public BlackCatPage()
{
StackLayout mainStack = new StackLayout();
StackLayout textStack = new StackLayout
{
Padding = new Thickness(5), Spacing = 10
};
Assembly assembly = GetType().GetTypeInfo().Assembly;
string resource = "BlackCat.Texts.TheBlackCat.txt";
using (Stream stream = assembly.GetManifestResourceStream (resource))
{
using (StreamReader reader = new StreamReader (stream))
{
bool gotTitle = false; string line;
while (null != (line = reader.ReadLine()))
{
Label label = new Label
{
Text = line,
if (!gotTitle)
{
Add first label (the title) to mainStack. label.HorizontalOptions = LayoutOptions.Center;
label.FontSize = Device.GetNamedSize(NamedSize.Medium, label);
label.FontAttributes = FontAttributes.Bold;
mainStack.Children.Add(label); gotTitle = true;
}
else
{

}
FillAndExpand. ScrollView scrollView = new ScrollView
{
Content = textStack, VerticalOptions = LayoutOptions.FillAndExpand, Padding = new Thickness(5, 0),
};
mainStack. mainStack.Children.Add(scrollView);

mainStack. Content = mainStack;
BackgroundColor = Color.White;
page. Padding = new Thickness (0, Device.OnPlatform (20, 0, 0), 0, 0);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote