如何将300x300宽度和高度images[1]
的图像绑定到xaml?
public class TrackSpotify
{
public class ExternalUrls
{
public string spotify { get; set; }
}
public class Image
{
public int height { get; set; }
public string url { get; set; }
public int width { get; set; }
}
public class Item
{
public string album_type { get; set; }
public List<string> available_markets { get; set; }
public ExternalUrls external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public List<Image> images { get; set; }
public string name { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Albums
{
public string href { get; set; }
public List<Item> items { get; set; }
public int limit { get; set; }
public string next { get; set; }
public int offset { get; set; }
public object previous { get; set; }
public int total { get; set; }
}
public class RootObject
{
public Albums albums { get; set; }
}
}
"images" : [ {
"height" : 640,
"url" : "i.scdn.co/image/8642802d13a53541e313781c34521a0d33099aac",
"width" : 640
}, {
"height" : 300,
"url" : "..................",
"width" : 300
}, {
"height" : 64,
"url" : "....................",
"width" : 64
} ],
<Grid.RowDefinitions>
<RowDefinition Height="200"></RowDefinition>
<RowDefinition Height="140"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<Image Source="{Binding url}"></Image>
</StackPanel>
<Grid Grid.Row="1">
<StackPanel VerticalAlignment="Top" Margin="10">
<TextBlock Text="{Binding name}" Foreground="#D4D4D4" FontSize="12"></TextBlock>
<TextBlock Text="{Binding album_type}" Foreground="#404040" FontSize="15" FontWeight="SemiBold"></TextBlock>
</StackPanel>
</Grid>
</Grid>
</DataTemplate>
var arrays = JsonConvert.DeserializeObject<NewReleaseSpotify.RootObject>(query);
spotifyItems.ItemsSource = arrays.albums.items;
答案 0 :(得分:-1)
我理解这不是真实的,因为你得到一个列表而不是接收单个图像,你可以做的是创建一个转换器绑定图像列表或类并返回你想要的图像。首先尝试返回字符串,如果它不起作用(取决于平台),请尝试使用您想要的URL返回一个新的BitmapImage。
你可以在BitmapImage中设置大小(它使处理速度更快),并且也可以设置大小。