but the ad_gallery_guid is unknown inside HomePageData()
jrahma
public static string ad_guid { get; set; }
public string ad_gallery_guid { get; set; }
In a class first execute the constructor, then assign a value to the property. So it's not possible to get the value of an attribute directly through a constructor unless the property is static, that's why you can get ad_guid but not ad_gallery_guid.
You can try below code, get ad_gallery_guid in get{}.
public ObservableCollection<AdGalleryData> gallery
{
get
{
ObservableCollection<AdGalleryData> data = new ObservableCollection<AdGalleryData>();
gallery.Add(new AdGalleryData() { gallery_image = "https://www.zeera.online/gallery/ads/" + HomePageData.ad_guid + "/" + ad_gallery_guid + ".png" });
return data;
}
set { gallery1 = value; }
}
Best regards,
Sam.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
public class HomePageData
{
public int ad_id { get; set; }
public static string ad_guid { get; set; }
public string ad_gallery_guid { get; set; }
public string user_guid { get; set; }
public string display_name { get; set; }
public string ad_currency { get; set; }
public double? ad_price { get; set; }
public DateTime created_date { get; set; }
/*
public ObservableCollection<AdGalleryData> gallery
{
get { return gallery1; }
set { gallery1 = value; }
}
*/
public ObservableCollection<AdGalleryData> gallery
{
get
{
ObservableCollection<AdGalleryData> data = new ObservableCollection<AdGalleryData>();
gallery.Add(new AdGalleryData() { gallery_image = "https://www.zeera.online/gallery/ads/" + HomePageData.ad_guid + "/" + ad_gallery_guid + ".png" });
return data;
}
set { gallery1 = value; }
}
public ObservableCollection<AdGalleryData> gallery1 = new ObservableCollection<AdGalleryData>();
public HomePageData()
{
gallery.Add(new AdGalleryData());
// gallery.Add(new AdGalleryData() { gallery_image = "https://www.zeera.online/gallery/ads/" + ad_guid + "/" + gallery[0].ad_guid + ".png" });
gallery.Add(new AdGalleryData() { gallery_image = string.Format("https://www.zeera.online/gallery/ads/{0}/{1}.png", ad_guid, ad_gallery_guid) });
// CONSOLE OUTPUT TEMP
System.Diagnostics.Debug.WriteLine("STARTING OUTPUT GALLERY");
for (int i = 0; i < gallery.Count; i++)
{
System.Diagnostics.Debug.WriteLine(string.Format("https://www.zeera.online/gallery/ads/{0}/{1}.png", gallery[i].ad_guid, gallery[i].ad_gallery_guid));
}
System.Diagnostics.Debug.WriteLine("COMPLETED OUTPUT GALLERY");
// CONSOLE OUTPUT TEMP
}
}
public class AdGalleryData
{
public string ad_guid { get; set; }
public string ad_gallery_guid { get; set; }
private string gallery_image1 = "https://www.zeera.online/gallery/ads/25914ccb-7dd2-11e9-be21-0cc47a4422ec/8ac825c0-8399-11e9-be21-0cc47a4422ec.png";
public string gallery_image
{
get
{
return gallery_image1;
// return string.Format("https://www.zeera.online/gallery/ads/{0}/{1}.png", HomePageData.ad_guid, ad_gallery_guid);
}
set { gallery_image1 = value; }
}
public AdGalleryData()
{
}
}
and populating the data here:
public async void populate_homepage()
{
sort_by = Preferences.Get("HomePageSortBy", "ad_id");
sort_direction = Preferences.Get("HomePageSortDirection", "DESC");
var client = new HttpClient();
client.BaseAddress = new Uri("https://www.jassimrahma.net/temp/populate_homepage_ads.php");
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("language", "EN"),
new KeyValuePair<string, string>("sort_by", sort_by),
new KeyValuePair<string, string>("sort_direction", sort_direction)
});
var response = await client.PostAsync("https://www.jassimrahma.net/temp/populate_homepage_ads.php", content);
var data = await response.Content.ReadAsStringAsync();
var result1 = JsonConvert.DeserializeObject<List<HomePageData>>(data);
var result = result1.Distinct<HomePageData>(new ItemEqualityComparer());
ObservableCollection<HomePageData> trends;
ObservableCollection<ObservableCollection<AdGalleryData>> datas = new ObservableCollection<ObservableCollection<AdGalleryData>>();
if (result != null)
{
trends = new ObservableCollection<HomePageData>(result);
}
else
{
trends = new ObservableCollection<HomePageData>();
var gallery = new ObservableCollection<AdGalleryData>();
datas.Add(gallery);
for (int i = 0; i < datas.Count; i++)
{
trends.Add(new HomePageData() { gallery = datas[i] });
}
}
ListViewHomePage.ItemsSource = trends;
loadingHomePage.IsVisible = false;
ListViewHomePage.IsVisible = true;
}
Member
23 Points
683 Posts
Getting Ads and Ad Gallery to ListView
Aug 06, 2019 09:44 AM|jrahma|LINK
Hi,
I have below code in my project.
and I am populating the data from my database like this:
Every ad is having multiple ad gallery [photo]
I have no issue getting the ads listed but how can I add the gallery?
the photo url is like this:
https://www.zeera.online/gallery/ads/[[[ad_guid]]]/[[[ad_guid]]].png
both ad_guid and ad_gallery_guid coming from the same populate_homepage_ads.php above
so how can I pass that to the public HomePageData()?
I tried to do it this way:
gallery.Add(new AdGalleryData() { gallery_image = "https://www.zeera.online/gallery/ads/" + ad_guid + "/" + ad_gallery_guid + ".png" });
but the ad_gallery_guid is unknown inside HomePageData()
Kindly help...
Thanks,
Jassim
Technology News @ www.JassimRahma.com
Contributor
3370 Points
1409 Posts
Re: Getting Ads and Ad Gallery to ListView
Aug 15, 2019 10:22 AM|samwu|LINK
Hi jrahma,
I'm sorry for not answering your question in time.
In a class first execute the constructor, then assign a value to the property. So it's not possible to get the value of an attribute directly through a constructor unless the property is static, that's why you can get ad_guid but not ad_gallery_guid.
You can try below code, get ad_gallery_guid in get{}.
Best regards,
Sam.
Member
23 Points
683 Posts
Re: Getting Ads and Ad Gallery to ListView
Aug 16, 2019 12:12 PM|jrahma|LINK
No Worries Sam
So you recommend to set ad_gallery_guid as static in this case?
From your above fix,
i changed my code as you can see below but it's not showing the data and here is the link:
https://www.jassimrahma.net/temp/populate_homepage_ads.php
and populating the data here:
Technology News @ www.JassimRahma.com