Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用JSON显示来自资产的图像-Windows Phone 8_C#_Json_Windows Phone 8_Windows Phone - Fatal编程技术网

C# 使用JSON显示来自资产的图像-Windows Phone 8

C# 使用JSON显示来自资产的图像-Windows Phone 8,c#,json,windows-phone-8,windows-phone,C#,Json,Windows Phone 8,Windows Phone,我正在制作一个WP8应用程序,在我的资产文件夹中有很多本地内容。因此,我使用存储在JSON文件夹中的JSON文件 我已经能够非常轻松地将JSON解析为C#,现在我正在尝试在列表中显示数据。我在显示标题方面没有问题,但我无法显示图像,即使使用我得到的文件名也是如此 我的图像存储在“Assets/Content/mediaXXX.jpg”中 列表视图模型: public class ListViewModel { public string Title { get; set

我正在制作一个WP8应用程序,在我的资产文件夹中有很多本地内容。因此,我使用存储在JSON文件夹中的JSON文件

我已经能够非常轻松地将JSON解析为C#,现在我正在尝试在列表中显示数据。我在显示标题方面没有问题,但我无法显示图像,即使使用我得到的文件名也是如此

我的图像存储在“Assets/Content/mediaXXX.jpg”中

列表视图模型:

 public class ListViewModel
    {
        public string Title { get; set; }
        public string Subtitle { get; set; }
        public BitmapImage ListImage { get; set; }
    }
XAML

 <ListBox Margin="0,1,0,0"
                 Height="730"
                 x:Name="MainList">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid Height="120"
                      Width="480">
                        <StackPanel Orientation="Horizontal">
                            <Image HorizontalAlignment="Left"
                               Source="{Binding ListImage}"
                               Margin="12"
                               Stretch="UniformToFill"
                               Width="130"/>
                            <Grid>
                                <TextBlock x:Name="ListItemTitle"
                                           Text="{Binding Title}"/>
                                <TextBlock x:Name="ListItemSubTitle"
                                       Text="{Binding Subtitle}"/>
                            </Grid>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

有什么想法吗

代码应该可以工作。唯一可能出现的问题是
列表框
数据绑定的定义不正确

我没有看到任何
.ItemsSource=
ItemsSource={绑定某些集合}

另一件事是确保
photo.filename
返回正确的文件

设置一个字符串debug_string=“Assets/Content/”+photo.filename+“.jpg”

确保一切都是正确的


最后一件事是确保文件实际位于项目及其子系统中的Assets文件夹中

BuildAction
设置为
Content

像这样


是的,这最后一步花了我几个小时=)
    BitmapImage image = new BitmapImage(new Uri(@"Assets/Content/" + photo.filename + ".jpg", UriKind.Relative);
    l.ListImage = image;