VintaSoft Imaging .NET SDK and Plug-ins Discussions

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

Board index < VintaSoft Imaging < VintaSoft Imaging .NET SDK and Plug-ins Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

How to show the filename in the thumbnailviewer



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:
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


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:
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


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


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:
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


Re: How to show the filename in the thumbnailviewer

Post by Ektoplasma »

Hi Alex,

thank you, this works :-)

Heinz


Page 1 from 1: 1