问题描述
我有一个在 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 (将#修改为@)