Variable does not exist in the current context, In my other project it is the same and works ?

SodiKZ125SodiKZ125 ✭✭Member ✭✭

Hi, I'm currently facing a frustrating problem with a project I have. I'm literally copying my previous project's code but it is saying that 2 public variables do not exist in the current context but its the exact same in my other problem but its working fine. Here is a picture of my working script:

But when I do this with my new project it can not find the exact same match and this is what I get:

I am very adamant that I have not missed out of spellings or class names so I have no idea what I am doing wrong, can anybody help with this? Below is my page.cs and DescriptionAccordionView.cs:

FormPage.xaml.cs:

    `using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    //using PCLStorage;

    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;

    namespace JGRJobSheet
    {
        public class JobSheetPageObject
        {
            public string Id { get; set; }
            public string CustomerName { get; set; }
            public string SiteAddress { get; set; }
            public string CustomerJobNumber { get; set; }
            public string JGRJobNumber { get; set; }
            public string CompletedBy { get; set; }
            public string Position { get; set; }
            public DateTime Date { get; set; }
            public SectionDescription Description { get; set; }
            public SectionLocation Location { get; set; }
            public string SubInvoiceTotal { get; set; }
            public string ValueAddedTax { get; set; }
            public string TotalInvoice { get; set; }
            public string PrintCustomerName { get; set; }
            public DateTime CompletionDate { get; set; }
        }

        [XamlCompilation(XamlCompilationOptions.Compile)]
        public partial class FormPage : ContentPage
        {
            JobSheetPageObject JobSheetobject = new JobSheetPageObject();

            public FormPage()
            {
                InitializeComponent();  
            }

            public FormPage(JobSheetPageObject JobSheetobject)
            {
                InitializeComponent();
                this.JobSheetobject = JobSheetobject;

                CustomerNameEntry.Text = JobSheetobject.CustomerName;
                SiteAddressEntry.Text = JobSheetobject.SiteAddress;
                CustomerJobNoEntry.Text = JobSheetobject.CustomerJobNumber;
                JgrJobNoEntry.Text = JobSheetobject.JGRJobNumber;
                AssessmentByEntry.Text = JobSheetobject.CompletedBy;
                PositionEntry.Text = JobSheetobject.Position;
                DateAndTimePicker.Date = JobSheetobject.Date;

                Description.SetSectionVehicles(JobSheetobject.Description);
                Location.SetSectionLocation(JobSheetobject.Location);

                SubInvoiceTotal.Text = JobSheetobject.SubInvoiceTotal;
                ValueAddedTax.Text = JobSheetobject.ValueAddedTax;
                TotalInvoice.Text = JobSheetobject.TotalInvoice;
                CustomerPrintName.Text = JobSheetobject.PrintCustomerName;
                FormCompletionDate.Date = JobSheetobject.CompletionDate;
            }

            private async void SubmitButton_Clicked(object sender, EventArgs e)
            {
                JobSheetobject = new JobSheetPageObject()
                {
                    Id = Convert.ToString(FormHub.rootobject.JobSheetobjects.Count + 1),
                    CustomerName = CustomerNameEntry.Text,
                    SiteAddress = SiteAddressEntry.Text,
                    CustomerJobNumber = CustomerJobNoEntry.Text,
                    JGRJobNumber = JgrJobNoEntry.Text,
                    CompletedBy = AssessmentByEntry.Text,
                    Position = PositionEntry.Text,
                    Date = DateAndTimePicker.Date,
                    Description = Descripton.GetSectionDescription(),
                    Location = Location.GetSectionDescription(),

                    SubInvoiceTotal = SubInvoiceTotal.Text,
                    ValueAddedTax = ValueAddedTax.Text,
                    TotalInvoice = TotalInvoice.Text,
                    PrintCustomerName = CustomerPrintName.Text,
                    CompletionDate = FormCompletionDate.Date
                };

                FormHub.rootobject.JobSheetobjects.Add(JobSheetobject);
                FormHub.SaveJSON();

                await DisplayAlert("JGR Job Sheet", "Job Sheet has been completed sucessfully", "Ok");
                await Navigation.PopModalAsync();
            }
        }
    }`

DescriptionAccordionView.xaml.cs:

    `using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    //using PCLStorage;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using JGRJobSheet;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;

    namespace JGRJobSheet
    {
        public class SectionDescription
        {
            public string Description { get; set; }
        }

        [XamlCompilation(XamlCompilationOptions.Compile)]
        public partial class DescriptionAccordionView : ContentView
        {

            public DescriptionAccordionView()
            {
                InitializeComponent();
            }

            public SectionDescription GetSectionDescription()
            {
                return new SectionDescription
                {
                    Description = DescriptionEditor.Text
                };
            }

            public void SetSectionDescription(SectionDescription description)
            {
                DescriptionEditor.Text = description.Description;
            }
        }
    }`
Tagged:

Posts

  • SodiKZ125SodiKZ125 ✭✭ Member ✭✭

    Solved: I didn't have a x:Name set in the XAML

Sign In or Register to comment.