开发者

Having a line break in listbox windows phone 7

Hi i am currently retrieving multi开发者_开发问答ple images from isolated storage. When i retrieve the image in the listbox1 all the image are joined one after another is it possible to have a line break in between each image?? Below will be my retrieve code and save code of the image to and from isolated storage.

Save code:

    private void SaveToLocalStorage(string imageFolder, string imageFileName)
    {
        imageFileName = App.imagePath;

        var isf = IsolatedStorageFile.GetUserStoreForApplication();
        if (!isf.DirectoryExists(imageFolder))
        {
            isf.CreateDirectory(imageFolder);
        }

        string filePath = Path.Combine(imageFolder, imageFileName);
        using (var stream = isf.CreateFile(filePath))
        {
            var bmp = new WriteableBitmap(inkCanvas, inkCanvas.RenderTransform);
            bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
        }
        MessageBox.Show(filePath            }

Retrieve code:

private void LoadFromLocalStorage(string imageFolder)
{
    var isoFile = IsolatedStorageFile.GetUserStoreForApplication();

    // Check if directory exists
    if(!isoFile.DirectoryExists(imageFolder))
    {
        throw new Exception("Image directory not found");
    }

    // Clear listbox
    listBox1.Items.Clear();

    // Get files
    foreach(string fileName in isoFile.GetFileNames())
    {
        string filePath = Path.Combine(imageFolder, fileName);
        using(var imageStream = isoFile.OpenFile(filePath, FileMode.Open, FileAccess.Read))
        {
            var imageSource = PictureDecoder.DecodeJpeg(imageStream);

            BitmapImage bi = new BitmapImage();

            ListBoxItem item = new ListBoxItem();
            bi.SetSource(imageStream);
            item.Content = new Image() { Source = bi, MaxHeight = 100, MaxWidth = 100 };
            listBox1.Items.Add(item);
        }
    }
}

Can anyone help me with how should i go about doing the line break in listbox1. Appreciate all of your help.


A line break isn't appropriate here as you're not breaking text.

I'm guessing what you realy want is some space between the items. For this you woudl use a margin.
Something like:

item.Content = new Image 
                   { 
                       Source = bi,
                       MaxHeight = 100,
                       MaxWidth = 100,
                       Margin = new Thickness(0, 0, 0, 20)
                   };

This puts 20 pixels space below each image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜