Reputation: 321
In Xamarin, I have pasted the following code from a working activity into a blank new activity:
[Activity (Label = "SimpleOnePageViewPager", MainLauncher = true)]
public class MainActivity : FragmentActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
FragmentItem fragItem = new FragmentItem ();
List<Android.Support.V4.App.Fragment> fragments = new List<Android.Support.V4.App.Fragment>();
fragments.Add(fragItem);
ViewPagerAdapter pageAdapter = new ViewPagerAdapter(SupportFragmentManager, fragments);
var pager = FindViewById<ViewPager>(Resource.Id.MainViewPager);
pager.Adapter = pageAdapter;
}
}
This is the error that I am getting?
Error CS0103: The name 'Resource' does not exist in the current context
Can I please have some help with this code?
Thanks in advance
Upvotes: 1
Views: 8650
Reputation: 1302
I met same problem today. I searched around, and also tried above solutions, but it did not work from my side. I already resolved the problem by myself with bellow steps:
P/S: hope it can help others if they meet same problem.
Happy coding!
Upvotes: 0
Reputation: 11
I had this problem too, and solved with this steps:
Open MainActivity.cs
of the Android project and put the line:
using AppName.Droid
This line is the name of namespace in the file Resource.designer.cs
Upvotes: 1
Reputation: 61
It was exactly the problem that I just solved, I think that this is a Xamarin Bug, when you add an existing xaml file it add it to the project without set it as embedded resource as it should be, and without set the custom tool command that must be set to: MSBuild:UpdateDesignTimeXaml
Upvotes: 0
Reputation: 1094
You can change the MainActivity.cs Build Action property as 'none' instead of 'compile'. I Hope this will resolve your problem.
Thanks, Imman
Upvotes: 0