如何解决如何在后面的代码中将图像嵌入到 ListView 中?
我有一个在 XAML 中创建的 ListView 并绑定到后面的 C# 代码中的列表。
我正在尝试从 C# 中将嵌入的图像插入到 ListView 中,但不确定我是如何失败的。
这是我的 XAML
<ListView x:Name="listView" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Padding="5">
<Image Source="{Binding ImageUrl}"/>
<StackLayout HorizontalOptions="StartAndExpand">
<Label Text="{Binding Name}"/>
<Label Text="{Binding Status}" TextColor="Gray"/>
</StackLayout>
<Button Text="Follow"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这是我的 C# 代码
public ListPage()
{
InitializeComponent();
Image embeddedImage = new Image
{
Source = ImageSource.Fromresource("App2.Images.image.jpg")
};
listView.ItemsSource = new List<Contact>
{
new Contact {Name = "Name",Status = "Hi!",ImageUrl = new Image{ Source = ImageSource.Fromresource("App2.Images.cat.jpg")} },new Contact {Name = "John",Status = "Bye!" },new Contact {Name = "Jennifer"}
};
}
这是我的联系人模型
public class Contact
{
public string Name { get; set; }
public string Status { get; set; }
public Image ImageUrl { get; set; }
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。