“Placeholder does not exist in current context”

前端 未结 1 358
面向向阳花
面向向阳花 2021-01-23 12:55

I am trying to make a Navigation bar in Xamarin. I created a Context view with an x:name of Placeholder in my MainPage.xaml and when I go to call it in the xaml.cs page it says

1条回答
  •  隐瞒了意图╮
    2021-01-23 13:30

    Your Page class is simply missing the call to InitializeComponent. That is a method call to the partial class of the page which will internally do some processing for the XAML file (more information can be found here).

    public partial class HomePage : ContentPage
    {
        public HomePage()
        {
            InitializeComponent();
        } 
    
        void Icon1_Tapped (object sender, System.EventArgs e)
        {
            var page = new HomePage();
            PlaceHolder.ContentView = page.Content;
    
        }
    }
    

    Also please make sure the xaml file has the class type correctly set. In case you are using a ContentPage, you should have something like this:

    
    
    
    
    

    0 讨论(0)
提交回复
热议问题