Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Assuming you are referring to a resource file in Xamarin, you can locate the resource by using its Id as follows:

  1. In your Xamarin project, go to the Resources folder and open the file where your resource Id is defined (e.g. Resource.Designer.cs for Android or Resource.Designer.cs for iOS)

  2. Look for the Id of the resource you want to locate. It should be defined as a constant in the resource file.

For Android, it will be defined as a static integer in the Resource class, for example:

public static int myResource = 2137090000;

For iOS, it will be defined as a static string in the Resource class, for example:

public static string myResource = "myResource.png";

  1. Once you have the resource Id, you can use it to locate the resource programmatically. For example, in Android, you can retrieve the resource using the Resources class as follows:

var resource = Resources.GetDrawable(Resource.myResource);

In iOS, you can retrieve the resource using the NSBundle class as follows:

var resource = UIImage.FromBundle(Resource.myResource);

To search for a resource by its name, you can use the Resources class again in Android as follows:

var resourceId = Resources.GetIdentifier("myResourceName", "drawable", PackageName); var resource = Resources.GetDrawable(resourceId);

And in iOS, you can use the NSBundle class as follows:

var resource = UIImage.FromBundle("myResourceName.png");

Note that the way you search for a resource by its name may vary depending on the type of resource (e.g. drawable, layout, string) and the platform you are targeting.