How to set ImageSource as Xamarin.Forms.Button?

后端 未结 6 1418
野性不改
野性不改 2021-01-04 11:28

I am trying add a background image using the image property in button. The issue I\'m facing is that i can\'t set StreamImageSource as button background. I encountered the e

6条回答
  •  旧时难觅i
    2021-01-04 12:20

    ImageSource.FromStream () returns a StreamImageSource (see docs). Button.Image accepts only FileImageSource (see docs).

    It means that what you're trying to achieve won't work, no matter how hard you try to cast one into the other.

    Button.Image will accept images stored as resources in your platform projects, and loaded either with:

    Icon.Image = ImageSource.FromFile ("foobar.png");
    

    or

    Icon.Image = "foobar.png";
    

提交回复
热议问题