0

I got a bit stuck on a problem and I was wondered if it's possible you can make a video on my problem it seems may others may have the same problem but, I been looking online but no real straight forward solution to the issue. The problem is, for instance, I have a stack layout in a content page page1.xaml and I added labels to that page 4 of them and I set properties for those labels setters and getters. however, if I make page2.xaml how would I be able to move the labels along with the data to page2.xaml basically reuse the data/labels declared from page1.xaml to page2.xaml throughout the app? here is what I have so far.

    <StackLayout>


    <StackLayout x:Name = "CustomerOrderStackLayout" Orientation = "Horizontal" HorizontalOptions = "Center" Padding = "20" >
    <Label x:Name ="CustomerOrderNumberLabel" HorizontalOptions = "Center" />
    </StackLayout>

    <StackLayout Orientation = "Vertical" Padding = "20" >
    <Label x:Name ="CustomerFirstNameLabel" 
           VerticalOptions = "Start" />
    <Label x:Name ="CustomerLastNameLabel" 
           VerticalOptions = "Start" />
    <Label x:Name ="CustomerAddressLabel" 
           VerticalOptions = "Start" />
    <Label x:Name ="CustomerZipCodeLabel" 
           VerticalOptions = "Start"/>
    <Label x:Name ="CustomerPhoneNumberLabel" 
           VerticalOptions = "Start"/>
    </StackLayout>
    </StackLayout>

</ContentPage>





 public partial class CustomerInfoContentV : ContentPage
        {
        public CustomerInfoContentV()
        {
            InitializeComponent();

            orderNum = "N";
            FirstName = "Nl";
            LastName = "Jk";
            Address = "203030 drive";
            ZipCode = "77088";
            PhoneNumber = "833-223-2222";
        }

        public string orderNum
        {
            get
            {
                return CustomerOrderNumberLabel.Text;
            }

            set
            {
                CustomerOrderNumberLabel.Text = value;
            }

        }
        public string FirstName
        {
            get
            {
                return CustomerFirstNameLabel.Text;
            }
            set
            {
                CustomerFirstNameLabel.Text = value;
            }
        }
        public string LastName
        {
            get
            {
                return CustomerLastNameLabel.Text;
            }
            set
            {
                CustomerLastNameLabel.Text = value;

            }
        }
        public string Address
        {
            get
            {
                return CustomerAddressLabel.Text;
            }
            set
            {
                CustomerAddressLabel.Text = value;
            }
        }
        public string ZipCode
        {
            get
            {
                return CustomerZipCodeLabel.Text;
            }
            set
            {
                CustomerZipCodeLabel.Text = value;
            }
        }
           public string PhoneNumber
          {

            get
            {
                return CustomerPhoneNumberLabel.Text;
            }
            set
             {
                CustomerPhoneNumberLabel.Text = value;
             }


          }
      }

I want to know is there a way to take this what i have and reuse it on a whole different contentpage thats my issue i want to take this what i created and reuse it through out the app is this possible? can anyone lead me in the right direction! please thanks :)

Nijoel
  • 13
  • 8
  • i ran across this other StackOverflow which was a similar to what i need help on but did not work. just FYI. -> http://stackoverflow.com/questions/28473200/reusability-user-controls-of-xaml-in-xamarin-forms – Nijoel Aug 17 '16 at 16:46
  • You wanna create a page2. and use the same labels of the page1 is that what you say? – Marcos José Pérez Pérez Aug 17 '16 at 16:50
  • Yeah, @ Jose that is what I ideally want to do. – Nijoel Aug 17 '16 at 22:51
  • I found a similar post which was posted last year sometime but the lack of tags I guess didn't point me to the post but I found a solution. You have to inherit the page from a layout class e.g. Stack layout etc then reference the name space of the class in the page you desire in the xaml file and that's it. – Nijoel Aug 23 '16 at 03:22
  • Update to this comment ^^ i posted above. You have to inherit which-ever layout you want to use e.g. stacklayout, contentpage, absolute-layout etc. then go to the destination new content page and make a alias xmnls:(name of the alias)="clr-namespace; assembly="(name of the project workspace)" then after that reference it in the new file then thats it. – Nijoel Jan 16 '17 at 01:43

1 Answers1

1

If I am understanding you correct. You can use templates. https://developer.xamarin.com/guides/xamarin-forms/templates/control-templates/creating/ . For my projects I just create a code based template and render it whenever I want it and wherever I want them.

nishantvodoo
  • 835
  • 3
  • 17
  • 32