Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

XAML control 'does not exist in the current context'

$
0
0

I'm getting an intermittent error where my XAML codebehind complains that a control 'does not exist in the current context'.

This is my .xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp_Mobile.IncidentReport"
             Title="Report Incidents">
  <StackLayout Spacing="5" x:Name="layoutIncident">
    <Label Text="Incident Type:" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
    <Picker x:Name="IncidentTypePicker1" Title="Incident Type" HorizontalOptions="FillAndExpand">
      <Picker.Items>
        <x:String>Theft</x:String>
        <x:String>Fire</x:String>
        <x:String>Accident</x:String>
      </Picker.Items>
    </Picker>
    <Label Text="Incident Description:" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
    <Editor x:Name="IncidentDescription" WidthRequest="400" HeightRequest="200" />
    <Button Text="Submit" Clicked="OnButtonClicked" />
    <Label x:Name="lblMessage" Text="" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
  </StackLayout>
</ContentPage>

And this is my .xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;

namespace MyApp_Mobile
{
    public partial class IncidentReport : ContentPage
    {
        int count = 0;

        public IncidentReport()
        {
            InitializeComponent();
        }

        public void OnButtonClicked(object sender, EventArgs args)
        {
            lblMessage.Text = IncidentTypePicker1.SelectedIndex.ToString() + " " + IncidentDescription.Text;

            count++;
            ((Button)sender).Text =
                String.Format("{0} click{1}!", count, count == 1 ? "" : "s");
        }
    }
}

The IDE (Visual Studio 2013) sometimes complains that IncidentTypePicker1 and IncidentDescription do not exist, and sometimes it does not complain and I am able to Build and Deploy the app. Is there any reason for this intermittent error?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>