首页 > 解决方案 > xamarin 页面顶部出现意外蓝线

问题描述

开发商!我刚开始学习 Xamarin,我创建了几个页面。它是如此简单。只需第一页和一个按钮即可获取第二页。但是当我点击按钮时,我的状态栏下出现了意想不到的蓝线。我该如何解决?先感谢您!

这是我的主页:

     <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
             x:Class="HelloApp.MainPage">

    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="MainPage.xaml"/>
        <!-- Place new controls here -->
        <Button x:Name="button1" Text="Go to Page 3" Clicked="Button_Click" />
        <!-- Place new controls here -->
    </StackLayout>

</ContentPage>

这是我的第二页:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="HelloApp.Page3">
    <ContentPage.Content>
        <StackLayout>
            <Label Text="Page3.xaml"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

这是我链接到第一个 xaml 的类的代码:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace HelloApp
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, EventArgs e)
        {
            Application.Current.MainPage = new NavigationPage(new Page3());
        }
    }
}

这是我链接到第二个 xaml 的类的代码:

   using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace HelloApp
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class Page3 : ContentPage
    {
        public Page3 ()
        {
            InitializeComponent ();
        }
    }
}

在此处输入图像描述 在此处输入图像描述

标签: c#xamarin

解决方案


Application.Current.MainPage = new Page3();

解决了!


推荐阅读