如何将ContentView添加到Click事件?

问题描述 投票:0回答:1

我的任务是创建一个程序,在主屏幕上显示两个按钮,我的名字和当前时间/日期。目标是在按下按钮之后显示一个通道,该按钮将使用整个屏幕。到目前为止,我已经创建了带有标签和按钮的主页面。但是,我很遗憾如何显示相对于点击按钮的段落。我使用经验适合的文本方式来充分利用屏幕。我已经创建了一个FontCalc.Cs页面,并在我拥有所有代码的主页中添加了onContentViewSizeChanged方法。我不知道接下来该怎么做。到目前为止,这是我在点击处理程序事件中的内容:

        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;

它不是在按钮消失的情况下显示通道,而是仅冻结android模拟器和UWP本地机器。

xamarin xamarin.forms xamarin.android xamarin.uwp
1个回答
0
投票

您可以在按钮单击时显示模态

        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);
         }

在ShowTextPage上,将HasNavigationBar设置为false

© www.soinside.com 2019 - 2024. All rights reserved.