Closed masonyc closed 5 years ago
@masonyc Can you please attach a small project that demonstrates this issue? Thanks!
@masonyc Can you please attach a small project that demonstrates this issue? Thanks!
App1.zip Hi @samhouts , I have attached the sample project above. It should display two images on the screen, one from iOS library and one from iOS project. But only the one from iOS project is shown.
OK. So, this is possible, but I think it works a little different than you expect. Find a working sample attached here based off your reproduction.
Basically what you do is described in the Docs here: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=macos#embedded-images
In case of your sample I had to create a new library because the one you included was an iOS specific one? So, I created a .NET Standard library for you. The principe is all the same though. Then, in that new library I added the image and set the build action to EmbeddedResource
. This will give you a ID you can get your file by which is basically your library name, any folder if you have them and your filename concatenated with dots. So in this case: NewImageLib.Images.test.png
.
Now, we make a reference between our shared code and this new library and we can start using the image.
Since we are loading this in a somewhat special way, this is not built into XAML (should it be @samhouts?) and we need to load the image through some code: ImageSource.FromResource("NewImageLib.Image.test.png", typeof(Class1).GetTypeInfo().Assembly)
. Note that I have added a dummy class Class1
to be able to resolve the right assembly so our app knows in which assembly to look for this particular image.
You can still do this with XAML as well, please refer to the earlier Docs link.
For some logistics; I don't think it's a bug but more of a question and I hope it's clear for you how to use this now. Because of this I will close the issue for now. If you feel this is not what you meant, feel free to comment of open it again.
Hope this helps!
@jfversluis What if I want set the Image in iOS lib, but allow iOS project override it if same name image exist? This is how Android works.
As far as I know, Android uses this very same mechanism in conjunction with Forms as also stated on the Docs page. But maybe I'm not understanding you correctly. Could you maybe elaborate a bit more on "how Android works" according to you?
Hi @jfversluis
if you have the above setup. you will see the logo.png from ClassLibrary1.
if you rename logo1.png --> logo.png in App4.Android, you will the logo.png from App4.Android
ClassLibrary1 | App4.Android |
---|---|
Sample Project
I must say, I didn't know that worked :)
I created an iOS counterpart for your sample app and it seems to work just like on Android?
Hi @jfversluis , in your sample project, if I rename logo1.png under App4iOS.iOS to logo.png. The application still shows YouTube Image in the Library project which is not behaving the same as Android. It should show the image of Intel if I renamed the png file under my startup iOS project.
Also please note, it works before version 3.6.0.344457. Starting at 3.6.0.344457, it does not behave like that anymore.
Make sure to do a rebuild. I’m a 100% sure it worked on my end with the sample I’ve attached
I am sure its a clean build. BTW your sample does not even have two logo.png file. What you had is logo1.png in iOS startup project and logo.png in Library. If you rename the logo1.png file, it does not work.
Very strange. I might need to check that out then, I’m sure I’ve seen it work.
Hi @jfversluis , sorry for the misleading comment on last week. I found out that you are actually right. The problem is when we use
Description
My Xamarin.Forms iOS project references an iOS lib that contains images and other stuffs, When I set Image Control's Source property to some image file from my iOS lib, the image is not displayed.
Similar question on stack overflow https://stackoverflow.com/questions/32566167/xamarin-how-to-load-image-from-ios-library-project
Steps to Reproduce
Expected Behavior
Image should be displayed.
Actual Behavior
Nothing displayed.
Basic Information