0
UWP Xamarin 프로젝트에 이미지 목록을 표시하려고합니다.Xamarin의 ListView에서 이미지를로드 할 수 없습니까?
ImageCell을 사용하고 싶지 않습니다.
이것은 Xamarin Forum의 샘플 코드입니다.
하지만 성공적으로 실행하려면이 코드를 완료 할 수 없습니다.
여기 내 코드입니다.
<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 Project의 자산 폴더에 noimage.png이 있습니다.
어떻게하면됩니까?
여전히 동일합니다. 이미지뿐만 아니라 제목과 부제목도 표시합니다. –
그러면 ImageSource.FromFile (String.Format ("{0} {1} .png", Device.OnPlatform ("아이콘 /", "자산"/ "이미지 없음"));'. 이미지가 플랫폼 프로젝트에 있어야하는 위치라면 파일 이름 만 전달하면됩니다. 따라서'ImageSource.FromFile ("noimage.png"));'를 사용해보십시오. – jgoldberger