问题
My assignment is to create a program that displays two buttons and my name and current time/date on the main screen. The goal is to have a passage appear once one of the buttons are pressed that will make use of the entire screen. So far, I have created the main page with the labels and buttons. However, I am very lost as to how to display the passage with respect to the button clicked. I am using the empirically fitting text way to make the best use of the screen. I have created a FontCalc.Cs page and added onContentViewSizeChanged method in the mainpage where I have all my code. I don't know how to proceed next. So far, this is what I have in my click handler event:
passage1Button.Clicked += (sender, args) =>
{
passage.Text = "So they began working together, each squadron leader commanding indivual pilots, " +
"Ender comanding the squadron leaders. They learned manyw ays of working together, " +
"as the simulator forced them to try different situations. Sometimes the simulator " +
"gave them a larger fleet to work with; Ender set them up then in three or four " +
"toons that consisted of three or four squadrons each. Sometimes the simulator gave " +
"them a single starship with its twelve fighters, and he chose three sqaudron leaders. ";
ContentView contentView = new ContentView
{
Content = passage
};
contentView.SizeChanged += onContentViewSizeChanged;
Instead of displaying the passage while having the buttons go away, it only freezes both the android emulator and the UWP local machine.
回答1:
You can show a modal on button click
passage1Button.Clicked += (sender, args) =>
{
var contentpage = new ShowTextPage("Passage text here, goes to page constructor where label is set to passed text");
var page = new NavigationPage(contentpage);
Navigation.PushModalAsync(page);
}
On the ShowTextPage, set HasNavigationBar to false
来源:https://stackoverflow.com/questions/55675568/how-to-add-a-contentview-to-a-click-event