XamlParseException when binding to a list

In my application, I allow users to save photos from the camera and photo library to isolated storage. Then I get the name of each file and read the photo and add to my list. When the list is created, I will attach it to the list.

I can get about 5 displayed without problems. After scrolling, I get an exception:

System.Windows.Markup.XamlParseException occurred
  Message= [Line: 0 Position: 0]
   --- Inner Exception ---
KeyNotFoundException

This is my 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>

This is the code:

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; }
}

Very new WP7 development and embarrassment as to why my code partially works.

+5
source share
2 answers

, : Name="{Binding FileName}"
(_) , :
,
, Tag.

+1

: XAMLParseException CRAZY!

, XmlParseException TargetInvocationException, InnerException. .

a:

try
{
}
catch(Exception ex)
{
}

catch. ex, , , .

0

All Articles