And*_*NET 5 c# xaml xamlparseexception windows-phone-7
在我的应用程序中,我允许用户将相机和照片库中的照片保存到隔离存储中.然后我获取每个文件的名称并阅读照片并添加到我的列表中.构建列表后,我将其绑定到列表框.
我可以大约5显示没有问题.滚动后我得到异常:
System.Windows.Markup.XamlParseException occurred
Message= [Line: 0 Position: 0]
--- Inner Exception ---
KeyNotFoundException
Run Code Online (Sandbox Code Playgroud)
这是我的XAML:
<ListBox x:Name="userPhotosListBox">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal">
<ContentControl Content="{Binding Image}" Width="400" />
<Image Name="{Binding FileName}" Source="/Images/appbar.delete.rest.png" Width="48" Height="48"
MouseLeftButtonUp="Image_MouseLeftButtonUp" VerticalAlignment="Center" HorizontalAlignment="Center" MaxWidth="48" MaxHeight="48" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
这是代码:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
var userFiles = store.GetFileNames();
foreach (var userFile in userFiles)
{
if (userFile.Contains(PhotoInIsolatedStoragePrefix))
{
var currentBitmap = ReadBitmapImageFromIso(userFile);
var userPhotoImage = new Image { Source = currentBitmap };
var userImg = new Img(userPhotoImage, userFile);
userPhotosListBox.Items.Add(userImg);
}
}
}
public class Img
{
public Img(Image img, string fileName)
{
this.Image = img;
this.FileName = fileName;
}
public Image Image { get; set; }
public string FileName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
WP7开发很新,并且为什么我的代码部分工作很困惑.