Page 1 of 1
How to show the filename in the thumbnailviewer
Posted: Sun Feb 16, 2014 9:34 pm
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
Re: How to show the filename in the thumbnailviewer
Posted: Mon Feb 17, 2014 11:45 am
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
Re: How to show the filename in the thumbnailviewer
Posted: Tue Feb 18, 2014 5:05 pm
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
Posted: Wed Feb 19, 2014 11:50 am
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
Re: How to show the filename in the thumbnailviewer
Posted: Thu Feb 20, 2014 2:02 pm
by Ektoplasma
Hi Alex,
thank you, this works
Heinz