jdstaerk
jdstaerk

Reputation: 892

CS0117 C# 'Resource' does not contain a definition for 'Drawable'

after I finally managed to setup a custom renderer, I wanna change the shape of every button in my app. Sounds easy, huh?

Setup:

Xamarin.Forms Version 2.3.2.127

Xamarin.Android.Support.* Version 23.3.0

My custom renderer:

var btn = this.Control as Android.Widget.Button;
btn.SetBackgroundResource(Resource.Drawable.arrow_button);

When I try to build & deploy it, the Error List gives me the following error:

CS0117  C# 'Resource' does not contain a definition for 'Drawable'

How can I resolve this error?

Cheers!

Upvotes: 4

Views: 9166

Answers (3)

Siim Kasepõld
Siim Kasepõld

Reputation: 69

I sort ran into similar error. It might that you are missing

using Android.Graphics.Drawables;

and make sure that your drawables are in png format, because jpg-s dont work. if this doesnt help, ill delete my answer

Upvotes: -1

jfmg
jfmg

Reputation: 2666

You are using the wrong Resource namespace. I had to use Droid.Resource in my project like this:

btn.SetBackgroundResource(Droid.Resource.Drawable.arrow_button);

Otherwise Xamarin doesn't know which Resource you mean, so you got to name it explicitly.

Upvotes: 2

Joe Healy
Joe Healy

Reputation: 5817

What I usually do when this one surfaces...

  • [right-mouse] droid project
  • open 'application' tab
  • set min android to android 4.4 / api19
  • hit [x] to close android manifest
  • [right-mouse] droid project
  • [click] open folder in in file explorer
  • delete "bin" and "obj" directories
  • rebuild PCL
  • rebuild Droid

Good luck. Healy in Tampa.

Upvotes: 1

Related Questions