1

This is my project structure

I declare ListView in XAML (MainPage.xaml):

<ListView x:Name="ShoppingListsLV"
              HorizontalOptions="CenterAndExpand"
              Margin="3"/>

And tried to access it from my code (MainPage.xaml.cs):

ShoppingListsLV.ItemsSource = new string[] { "test", "test 2"};

And I have an error:

CS0103: The name ShoppingListsLV does not exist in the current context

3 Answers3

1

Check that you are writing your code after the call:

InitializeComponent();

Also, check that your view is referencing the right code-behind file:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="YourNamespace.MainPage">

Finally, try to close VS, then go and delete from your projects folders the following ones:

Android - bin

Android - obj

iOS - bin

iOS - obj

This action will clear completely your cache. After this is done, reopen your solution in VS and perform a clear, re-build operation. Your references should be working fine now.

SergioAMG
  • 428
  • 2
  • 10
0

Change the page Custom Tool property to MSBuild:UpdateDesignTimeXaml where your list exists.

0

Your code is right, if you see the errors you need to build the app, it should work and you won't see the error anymore.

Ivan Ičin
  • 9,672
  • 5
  • 36
  • 57