我试图理解这个问题,但它根本没有工作......
所以我要做的就是制作一个带有listview的菜单作为它的内容。现在,我有视图,带有绑定属性,我有一个类,我在其中列出列表。这是代码:
public class MenuList
{
public ImageSource Icon { get; set; }
public String Title { get; set; }
// Initialize the Pokemon object thing :p
//public MenuList() { }
// Here we make the pokemon list :D
public static List<MenuList> GetMenuItems()
{
return new List<MenuList>()
{
new MenuList() { Icon="RadioApp.Assets.Icons_menu.account.png", Title="Radio" },
new MenuList() { Icon="RadioApp.Assets.Icons_menu.account.png", Title="Shout/request lijn" },
new MenuList() { Icon="RadioApp.Assets.Icons_menu.account.png", Title="Rooster" },
new MenuList() { Icon="RadioApp.Assets.Icons_menu.account.png", Title="Geschiedenis" },
new MenuList() { Icon="RadioApp.Assets.Icons_menu.account.png", Title="Medewerkers" },
new MenuList() { Icon="RadioApp.Assets.Icons_menu.account.png", Title="Over deze app" },
};
}
}
<ListView x:Name="menuItemsLVW" Grid.Row="0">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<StackLayout Orientation="Horizontal">
<Image Source="{Binding Icon}" />
<Label Text="{Binding Title}" TextColor="Black" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
现在,我收到错误:[0:] Binding: 'Icon' property not found on 'RadioApp.Model.MenuList', target property: 'Xamarin.Forms.Image.Source'
我不知道它为什么会返回错误,因为据我所知,这应该有用吗?
我创建页面的类:
public partial class Menu : ContentPage
{
private List<MenuList> lstOfAllMenuItems;
public Menu()
{
InitializeComponent();
lstOfAllMenuItems = MenuList.GetMenuItems();
menuItemsLVW.ItemsSource = lstOfAllMenuItems;
//Debug.WriteLine(lstOfAllMenuItems[0].Title);
//Debug.WriteLine(lstOfAllMenuItems[0].Icon);
}
}
如果我进行调试,它只返回正确的项目......