0

我使用默认模板创建了一个新项目,该模板已经包含一个登录按钮、注销按钮等。我按照教程一步一步创建了登录和注册。登录后,您将被重定向到主页。在我的主页中,弹出菜单不可见。

这是我的 LoginPage.xaml.cs 中的代码

namespace final1scratch.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class LoginPage : ContentPage
    {
        public LoginPage()
        {
            InitializeComponent();
            this.BindingContext = new LoginViewModel();
        }

   async void Handle_Clicked(object sender, System.EventArgs e)
    {
        await Navigation.PushAsync(new RegistrationPage());
    }

    async void Handle_Clicked_1(object sender, System.EventArgs e)
    {
        var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabse.db");
        var db = new SQLiteConnection(dbpath);
        var myquery = db.Table<RegUserTable>().Where(u => u.UserName.Equals(EntryUser.Text) && u.Password.Equals(EntryPassword.Text)).FirstOrDefault();
        if (myquery != null)
        {
            App.Current.MainPage = new NavigationPage(new HomePage());
        }

        else
        {
            Device.BeginInvokeOnMainThread(async () =>
            {
                var result = await this.DisplayAlert("Error", "Failed User Name and Password", "Yes", "Cancel");

                if (result)
                    await Navigation.PushAsync(new LoginPage());
                else
                {
                    await Navigation.PushAsync(new LoginPage());
                }

            });
        }
    }
}

这是我的 HomePage.xaml

<?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="final1scratch.Views.HomePage">
    <ContentPage.Content>
        <StackLayout>
            <Label Text="Welcome to Xamarin.Forms!"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />
            
            <Button Text="Logout" Clicked="Handle_Clicked" TextColor="Black"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

这是用户登录后的屏幕截图

点击查看图片

4

0 回答 0