Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to access x:Name of views of contentpade inside another contentpage class?

Med_Med_ Member ✭✭
Hello, i want to access x:Name of any view of contentpage from another contentpage class.
Like in the photo attached but that case is b/w contentpage and contentview.
My question is how to proceed in case both are contentpages

Best Answer


  • LandLuLandLu Member, Xamarin Team Xamurai

    x:Name couldn't be accessed outside the current page/view. We need to expose a public property in the class like:

    public StackLayout RootLayout;
    public MyPage()
        RootLayout = xamlRootLayout;

    This RootLayout indicates a control in xaml:

    <StackLayout x:Name="xamlRootLayout">

    Finally, the xaml control could be reached in this way.

  • Med_Med_ Member ✭✭
    Thank you for replying.
    In this case RootLayout is not detected .I think i ve to use<local:> in the xaml file where i want to apply in class but unfortunately it s shown content not supported, it works with contentview in contentpage.
    By declaring
    public static var Myvariable= MyXname;
    I can access the value but not changing it im managing with that for a while as i need only the value.
  • Med_Med_ Member ✭✭
    edited May 2020
    Thank you i think if i use return inside method in that way i can also change the value. I needed to get value your answer works fine and it s similar to what i did with public static where i don't intanciate and get directly Mypage.RootLayout
Sign In or Register to comment.