I'm trying to get some images to display in a listView with a label and an image using the embedded images in the shared project.
If I use something like this the image appears with no issues
calendarImg.Source = ImageSource.FromResource("OWst.Images.calendar.png");
Here's the key pieces of code that I'm using to generate my ListView menu with images. Any tips on what my disconnect here might be would be appreciated.
`class MenuCell : ViewCell
{
public MenuCell()
{
var imageImg = new Image
{
HorizontalOptions = LayoutOptions.Start,
HeightRequest = 40
};
imageImg.SetBinding(Image.SourceProperty, "ImageUri");
var textLbl = new Label
{
HorizontalOptions = LayoutOptions.FillAndExpand,
BackgroundColor = Color.FromHex("EEEEEE"),
TextColor = Color.FromHex("80A7D8"),
VerticalOptions = LayoutOptions.FillAndExpand
};
textLbl.SetBinding(Label.TextProperty, "ItemText");
var layout = new StackLayout()
{
Orientation = StackOrientation.Horizontal,
Children ={
imageImg,
textLbl
}
};
View = layout;
}
}`
The List DataSource
List<MenuItems> testMenu = new List<MenuItems>()
{
new MenuItems("Conference Schedule", "OWst.Images.calendar.png"),
new MenuItems("Personal Schedule", "OWst.Images.testImg.png"),
};
The assignment to the ListView
menu.ItemsSource = testMenu;
menu.ItemTemplate = new DataTemplate(typeof(MenuCell));
The Class for the Menu Items Strings
` class MenuItems
{
public MenuItems(string itemText, string imageUri)
{
ItemText = itemText;
ImageUri = imageUri;
}
public string ItemText { get; set; }
public string ImageUri { get; set; }
}
}`