This is a ridiculous question. How the F*** do you set the Image Source from the Code behind. IT should be as simple as:
imageName.Source = "My Remote Image served from a server somewhere";
After hours of trial and error and searching the web I am no closer to an answer.
my xaml.
<StackLayout x:Name="imgArray" HeightRequest="120" VerticalOptions="FillAndExpand" BackgroundColor="Purple"> <Image x:Name="bannerTest" HorizontalOptions="FillAndExpand" VerticalOptions="Fill" HeightRequest="120" /> </StackLayout>
If I do this in my Code Behind I get one image loaded.
public MainPage() { InitializeComponent(); ViewModel = new HomePageViewModel(); currentBannerIndex = 0; BindingContext = ViewModel; ViewModel.Banners.CollectionChanged += new NotifyCollectionChangedEventHandler(this.BannerCollectionChanged); bannerTest.Source = ImageSource.FromUri(new Uri("//images.myDomain.com/iphone_x_large.jpg")); }
Notice that Image URL is not real and doesn't exist. I am using a real URL in my code.
The above sets the image to the image pointed to in the URL. Great!
Now later when I am notified my collection has changed I then set a timer to update the Image Source to another URL when fired. Doing the following does nothing:
private void OnBannerTimerFired(object source, ElapsedEventArgs eArgs){ bannerTest.Source = ""; bannerTest.Source = ImageSource.FromUri(new Uri("//www.myDomaine.com/images/banners/home/FamousDom.jpg")); }
Note: the URLs do have the protocol in my code, this forum will not let me post a url.
What am I missing? Is it really more involved than that to change the bloody image?