我想在我的UWP Xamarin项目中显示一个图像列表 .
我不想使用ImageCell .
这是Xamarin论坛的示例代码 .
但我无法完成此代码以成功运行 .
这是我的代码 .
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout BackgroundColor="#eee"
Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Image Source="{Binding image}" />
<Label Text="{Binding title}"
TextColor="#f35e20" />
<Label Text="{Binding subtitle}"
HorizontalOptions="EndAndExpand"
TextColor="#503026" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
public class ImageItem {
string title;
ImageSource image;
string subtitle;
}
ImageItem a= new ImageItem();
a.title = "XXX";
a.image = ImageSource.FromFile(String.Format("{0}{1}.png", Device.OnPlatform("Icons/", "", "Assets/"), "noimage"));
a.subtitle = "XXX";
list.Add(a);
listview.itemsSource = list;
我在UWP Xamarin项目的Assets文件夹中有noimage.png .
我能怎么做?
1 回答
我相信如果你想使用绑定,你需要
ImageItem
来实现INotifyPropertyChanged
接口 . 您可以尝试设置类ImageItem,如下所示: