C# 在listview中绑定图像
我对xamarin比较陌生,目前我正在尝试将图像绑定到我的listview,但无论我尝试了什么,我似乎都无法让它们显示出来 这是我的密码: Xaml: 请注意,我已尝试将AviSource更改为ImageSource和一个字符串,但两者都不适用于我。我可以显示其他东西,但不能显示图像 有什么建议吗? 谢谢试试这个例子C# 在listview中绑定图像,c#,image,xaml,xamarin,xamarin.forms,C#,Image,Xaml,Xamarin,Xamarin.forms,我对xamarin比较陌生,目前我正在尝试将图像绑定到我的listview,但无论我尝试了什么,我似乎都无法让它们显示出来 这是我的密码: Xaml: 请注意,我已尝试将AviSource更改为ImageSource和一个字符串,但两者都不适用于我。我可以显示其他东西,但不能显示图像 有什么建议吗? 谢谢试试这个例子 <ListView ItemsSource="{Binding Monkeys}" HasUnevenRows="true&quo
<ListView ItemsSource="{Binding Monkeys}"
HasUnevenRows="true"
ItemSelected="OnListViewItemSelected"
ItemTapped="OnListViewItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.RowSpan="2"
Source="{Binding ImageUrl}"
Aspect="AspectFill"
HeightRequest="60"
WidthRequest="60" />
<Label Grid.Column="1"
Text="{Binding Name}"
FontAttributes="Bold" />
<Label Grid.Row="1"
Grid.Column="1"
Text="{Binding Location}"
VerticalOptions="End" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
此处链接说明]
- 我在这里发现了同样的问题
AviSource
应该是字符串,2)Source=“{Binding AviSource}”
,3)确保绑定到公共属性,4)项目中存储的“defaultAVI_48x48.jpg”在哪里?确保按照文档中的指定存储图像-绑定仅适用于公共属性。他们需要有一个get',并标记为public`如果这是一个问题,它将影响您的所有数据,而不仅仅是图像。您是否阅读了图像上的文档并验证了存储是否正确?我建议您再次阅读它们-“因为没有从string到ResourceImageSource的内置类型转换器,这些类型的图像无法由XAML本机加载。”
private void InitializeMembersBlank()
{
Members = new List<Member>();
for (int i = 0; i < App.UserDB.GetSpecificUser((int)App.Current.Properties["currentUser"]).MemeberNum; i++)
{
Members.Add(new Member
{
AviSource = new Image { Source = "defaultAVI_48x48.jpg" },
systemID = i,
name = "Member " + (i + 1)
}) ;
}
}
public class Member
{
public string name { get; set; }
public string pro_noun { get; set; }
public string birthday { get; set; }
public string role { get; set; }
public int systemID { get; set; } // how is this being set???
public string description { get; set; }
public Image AviSource { get; set; }
public override string ToString()
{
return "" + name + " /" + pro_noun + " /" + role + " /" + systemID;
}
}
<ListView ItemsSource="{Binding Monkeys}"
HasUnevenRows="true"
ItemSelected="OnListViewItemSelected"
ItemTapped="OnListViewItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.RowSpan="2"
Source="{Binding ImageUrl}"
Aspect="AspectFill"
HeightRequest="60"
WidthRequest="60" />
<Label Grid.Column="1"
Text="{Binding Name}"
FontAttributes="Bold" />
<Label Grid.Row="1"
Grid.Column="1"
Text="{Binding Location}"
VerticalOptions="End" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
TableView tableView = new TableView
{
Intent = TableIntent.Form,
Root = new TableRoot
{
new TableSection
{
new ImageCell
{
// Some differences with loading images in initial release.
ImageSource =
Device.OnPlatform(ImageSource.FromUri(new Uri("http://xamarin.com/images/index/ide-xamarin-studio.png")),
ImageSource.FromFile("ide_xamarin_studio.png"),
ImageSource.FromFile("Images/ide-xamarin-studio.png")),
Text = "This is an ImageCell",
Detail = "This is some detail text",
}
}
}
};