How to show the filename in the thumbnailviewer

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
Ektoplasma
Posts: 4
Joined: Sun Feb 16, 2014 9:07 pm

How to show the filename in the thumbnailviewer

Post by Ektoplasma »

Hello,

I would like to show the filename under each thumbnail. How would I do this?
Here is the code how I show the thumbnails by now:

Code: Select all

private void ShowThumbnails(string currentFolder)
{
       wpfThumbnailViewer1.Images.Clear();
       foreach (var file in Directory.GetFiles(currentFolder).Where(f => f.EndsWith(".png") || f.EndsWith(".jpg") || f.EndsWith(".jpeg")))
       {
            wpfThumbnailViewer1.Images.Add(file);
       }
}
I work with Visual Studio 10 Express, WPF and C#

Thank you for your help,
Heinz
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: How to show the filename in the thumbnailviewer

Post by Alex »

Hello Heinz,

Here is a code snippet which shows how to show text under each thumbnail:

Code: Select all

void MainWindow()
{
   ...
   thumbnailViewer1.ThumbnailAdded += new EventHandler<ThumbnailImageItemEventArgs>(thumbnailViewer_ThumbnailAdded);
   ...
}

void thumbnailViewer_ThumbnailAdded(object sender, ThumbnailImageItemEventArgs e)
{
    // add decoder name on thumbnail
    TextBlock text = new TextBlock();
    text.TextAlignment = TextAlignment.Center; 
    text.Text = e.Thumbnail.Source.SourceInfo.DecoderName;
    e.Thumbnail.Content = text;
}
Best regards, Alexander
Ektoplasma
Posts: 4
Joined: Sun Feb 16, 2014 9:07 pm

Re: How to show the filename in the thumbnailviewer

Post by Ektoplasma »

Hello Alex,

thank you for the code snippet.
It works fine, but the text appears not under but above each thumbnail.
And it does not create a new line when the text is larger then the image width.

I tried to find properties or methods but couldn't find anything.
Can you tell me how I could show the text under each thumbnail and let
the text create a newline when it is bigger the the image width?

Thank you
with best regards,
Heinz
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: How to show the filename in the thumbnailviewer

Post by Alex »

Hello Heinz,
Can you tell me how I could show the text under each thumbnail and let the text create a newline when it is bigger the the image width?
Here is the code snippet:

Code: Select all

void MainWindow()
{
    ...
    // increase the thumbnail height, this is necessary for reserving space for text under thumbnail
    thumbnailViewer.ThumbnailSize = new Size(thumbnailViewer.ThumbnailSize.Width, thumbnailViewer.ThumbnailSize.Height + 50);
    // subscribe to the ThumbnailAdded event
    thumbnailViewer1.ThumbnailAdded += new EventHandler<ThumbnailImageItemEventArgs>(thumbnailViewer_ThumbnailAdded);
    ...
}

void thumbnailViewer_ThumbnailAdded(object sender, ThumbnailImageItemEventArgs e)
{
    // reserve space for text
    Thickness thumbnailImagePadding = e.Thumbnail.ThumbnailImagePadding;
    thumbnailImagePadding.Bottom = 50;
    e.Thumbnail.ThumbnailImagePadding = thumbnailImagePadding;

    // create the text block with filename
    TextBlock text = new TextBlock();
    text.Text = e.Thumbnail.Source.SourceInfo.Filename;
    text.TextAlignment = TextAlignment.Center;
    text.TextWrapping = TextWrapping.Wrap;
    text.Margin = new Thickness(0, e.Thumbnail.Height - 50, 0, 0);
    // add text block as content of thumbnail
    e.Thumbnail.Content = text;
}
Best regards, Alexander
Ektoplasma
Posts: 4
Joined: Sun Feb 16, 2014 9:07 pm

Re: How to show the filename in the thumbnailviewer

Post by Ektoplasma »

Hi Alex,

thank you, this works :-)

Heinz
Post Reply