Hello,
Welcome to our Microsoft Q&A platform!
You can try to add a property to the NavMenuItem
class as follows:
public class NavMenuItem
{
public MenuItemType Id { get; set; }
public string Title { get; set; }
public string IconSource { get; set; }
// add the new property `Image` here , remember change the string.Format to yours.
public ImageSource Image
{
get
{
return ImageSource.FromResource(string.Format("WorkingWithImages.Images.{0}", IconSource));
// your code should be
//return ImageSource.FromResource(string.Format("EY365OCMobileApp.Images.{0}", IconSource));
}
}
}
And init menuItems
like this(remove the prefix of your images), for example:
menuItems = new List<NavMenuItem>
{
new NavMenuItem {Id = MenuItemType.Home, Title="Home",IconSource = "watermelon.png"},
new NavMenuItem {Id = MenuItemType.Offers, Title="Offerings", IconSource = "cabbage.png" },
new NavMenuItem {Id = MenuItemType.Assortment, Title="Assortment", IconSource = "cabbage.png" },
new NavMenuItem {Id = MenuItemType.Cart, Title="Your Cart", IconSource = "pepper.png" },
new NavMenuItem {Id = MenuItemType.Orders, Title="Your Orders", IconSource = "kiwifruit.png"},
new NavMenuItem {Id = MenuItemType.Wishlists, Title="Your Wishlists", IconSource = "cabbage.png"},
new NavMenuItem {Id = MenuItemType.Cases, Title="Your Questions / Problems", IconSource = "watermelon.png"},
new NavMenuItem {Id = MenuItemType.UserProfile, Title="Your Profile" },
};
And bind the new property Image
like this:
<Image Source="{Binding Image}" />
The whole usage:
<ListView x:Name="lstView" RowHeight="60">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" HorizontalOptions="Fill" BackgroundColor="Olive">
<StackLayout Orientation="Vertical">
<Label Text = "{Binding Title}" FontSize="24" AbsoluteLayout.LayoutBounds="0.25, 0.25, 400, 40"/>
<Label Text = "{Binding Id}" AbsoluteLayout.LayoutBounds="50, 35, 200, 25"/>
</StackLayout>
<Image Source="{Binding Image}" HorizontalOptions="End" AbsoluteLayout.LayoutBounds="250.25, 0.25, 50, 50 " WidthRequest="40" HeightRequest="40"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.