Linked Questions

Popular Questions

I load data from database to a listview by MVC Api and one of data to want to show is Image. Image saved in database like this "\images\NewsImage\Untitled-4.jpg" Now we have a website that show news with image that image address only save in database not image. This is my code to show data in list view Title is showing correctly but image did't show

`HttpClient httpClient = new HttpClient(); var response = await httpClient.GetStringAsync("http://somedomain.com/api/values/getlastten");

    var TProducts = JsonConvert.DeserializeObject<List<News>>(response);
    Label header = new Label
    {
        Text = "ten",
        FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
        HorizontalOptions = LayoutOptions.Center
    };

    ListView listView = new ListView
    {
        ItemsSource = TProducts,
        ItemTemplate = new DataTemplate(() =>
        {
            // Create views with bindings for displaying each property.
            Label nameLabel = new Label();
            nameLabel.SetBinding(Label.TextProperty, "Title");

            Image nImage = new Image();
            nImage.SetBinding (Image.SourceProperty, @"www.mydomain.com/"+"Image");

            Label ViewdLabel = new Label();
            ViewdLabel.SetBinding(Label.TextProperty, "Viewed");
            nameLabel.SetBinding(Label.FontFamilyProperty, "BNazanin.ttf#Nazanin");

            // Return an assembled ViewCell.
            return new ViewCell
            {
                View = new StackLayout
                {
                    Padding = new Thickness(0, 5),
                    Orientation = StackOrientation.Horizontal,
                    Children =
                        {
                            nImage,
                            new StackLayout
                            {
                                VerticalOptions = LayoutOptions.Center,
                                Spacing = 0,
                                Children =
                                {
                                    nameLabel,
                                    ViewdLabel
                                }
                                }
                        }
                }
            };
        })
    };
    listView.ItemSelected += async (sender, e) =>
    {
        News = (News)e.SelectedItem;

      await  Navigation.PushAsync(new NewsDetails(News));
    };
        this.Content = new StackLayout
    {
        Children =
        {
            header,
            listView
        }
    };

}


private void ProductLV_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
    News =(News) e.SelectedItem;

    Navigation.PushAsync(new NewsDetails(News));
}`

Update My model is

 public class News
{
    public int Id { get; set; }
    public string SubTitle { get; set; }
    public string Title { get; set; }
    public string Summery { get; set; }
    public string FullText { get; set; }
    public string Image { get; set; }

}

Related Questions