Как связать метку в MasterDetailPage и метку в ContentPage с записью со страницы входа? - PullRequest
1 голос
/ 26 января 2020

Это в моем Main.xaml.cs (ContentPage):

        public string Get_item { get; set; }

        public Main(string SelectedItem)
        {
            InitializeComponent();
            this.BindingContext = this;
        }

Это в моем MainPage.xaml.cs (MasterDetailPage):


 public string Get_item { get; set; }
        public MainPage(string SelectedItem)
        {
            InitializeComponent();
            Get_item = SelectedItem;
            this.BindingContext = this;

            menuList = new List<MasterPageItem>();
            SetValue(NavigationPage.HasNavigationBarProperty, false);
            // Adding menu items to menuList and you can define title ,page and icon
            menuList.Add(new MasterPageItem() { Title = "Home", Icon = "home_red.png", TargetType = typeof(Main) });
            menuList.Add(new MasterPageItem() { Title = "Settings", Icon = "setting_violet.png", TargetType = typeof(Settings) });           
            menuList.Add(new MasterPageItem() { Title = "LogOut", Icon = "yellow_logout.png", TargetType = typeof(Login) });
            // Setting our list to be ItemSource for ListView in MainPage.xaml
            navigationDrawerList.ItemsSource = menuList;
            // Initial navigation, this can be used for our home page

            Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(Main)));
        }

Это в my MainPage.xaml:


<Label Text="{Binding Get_item}" />

Метка из моей главной страницы (MasterDetailPage) отображает имя пользователя после входа в систему, как я делаю свой вход:


            var dbpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Userdatabase.db");
            var db = new SQLiteConnection(dbpath);
            var loginquery = db.Table<RegUserTable>().Where(u => u.Username.Equals(EntryLoginUsername.Text) && u.Password.Equals(EntryLoginPassword.Text)).FirstOrDefault();

            App.Current.MainPage = new NavigationPage(new MainPage(EntryLoginUsername.Text));


Я хочу, чтобы имя пользователя также появляется в моем Main (ContentPage), но когда я вхожу в систему, это выдает мне следующую ошибку: System.MissingMethodException: «Конструктор по умолчанию не найден для типа App1.Main»

Я не могу даже сделать это в моей MainPage (MasterDetailPage) :


Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(Main (EntryLoginUsername.Text)  )));


Какое действие я предприму, чтобы имя пользователя присутствовало в моих ContentPage и MasterDetailPage?

1 Ответ

0 голосов
/ 28 января 2020

Я уже выяснил, как Activator.CreateInstance будет иметь параметры:


Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(Main), UserLabel.Text));

это не даст вам ошибки: D

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...