<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ben Dewey - Web, XAML, and Cloud &#187; Binding Converter</title>
	<atom:link href="http://www.bendewey.com/index.php/tag/binding-converter/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bendewey.com</link>
	<description>Father, Developer, Microsoft MVP, Speaker, and Author</description>
	<lastBuildDate>Sat, 22 Mar 2025 05:04:02 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.8.41</generator>
	<item>
		<title>NativeFileTypeViewer : FileIconImageConverter &#8211; Convert a filename to the file system icon.</title>
		<link>http://www.bendewey.com/index.php/7/nativefiletypeviewer-fileiconimageconverter-convert-a-filename-to-the-file-system-icon</link>
		<comments>http://www.bendewey.com/index.php/7/nativefiletypeviewer-fileiconimageconverter-convert-a-filename-to-the-file-system-icon#comments</comments>
		<pubDate>Sat, 23 Feb 2008 02:44:20 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Binding Converter]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://bendewey.wordpress.com/?p=7</guid>
		<description><![CDATA[I&#8217;ve recently been creating more desktop applications and I often needed to print out the system icons for standard files.  In the past I had used Photoshop.]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve recently been creating more desktop applications and I often needed to print out the system icons for standard files.  In the past I had used Photoshop to crop out the icons and I ended up only supportting a limited number of file icons.  And as I was writing this post I also found a shell32 <a title="How to use the SHGetFileInfo function to get the icons that are associated with files in Visual C# .NET" href="http://support.microsoft.com/kb/319350" target="_blank">tatic</a>  used to create ImageLists in WinForms.</p>
<p>In order to load the system file icons and descriptions for my WPF applications, I built this Binding Converter.  The FileIconImageConverter.cs file is an IValueConverter that accepts  a filename or full file path.  The Converter supports caching and both 32-pixel and 16-pixel icons.  With the exception of the cache checking functionality, this converter has 4 main parts. First it creates a blank 0kb text file the the same extension as the source filename.  Second it loads a <a title="SHFILEINFO" href="http://msdn2.microsoft.com/en-us/library/bb759792(VS.85).aspx" target="_blank">SHFILEINFO</a> Struct using Win32.<a title="SHGetFileInfo" href="http://msdn2.microsoft.com/en-us/library/bb762179(VS.85).aspx" target="_blank">SHGetFileInfo</a> and creates an Icon from the handle. Third it creates Bitmap from the Icon and saves it to a MemoryStream as a PNG.  Finally it loads the ImageSource using a PngBitmapDecoder from the previous Memory Stream.</p>
<p>I would love to give credit to <a title="WPF - Assigning Icon to Image control" href="http://infosysblogs.com/microsoft/2007/04/wpf_assigning_icon_to_image_co.html" target="_blank">Atul Gupta&#8217;s Blog</a>, which help me out a lot with this.  I haven&#8217;t tried it in Silverlight, please let me know if you try it.  Please see my website for the full code.</p>
<p><a href="http://www.bendewey.com/code/FilenameIconImageConverter.html">http://www.bendewey.com/code/FilenameIconImageConverter.html</a></p>
<p>This little application, called the <a title="Full Code" href="http://www.bendewey.com/code/FilenameIconImageConverter.html" target="_blank">NativeFileTypeViewer</a> (<a title="Download Source Code" href="http://www.bendewey.com/code/NativeFileTypeViewer.zip" target="_blank">source code</a>), loads a directory and converts the filenames into the filename descriptions and the file icon, to demonstrate the use of the binding converters.</p>
<img src="http://www.bendewey.com/code/NativeFileTypeViewer.gif" border="0" alt="Native FileType Viewer" width="379" height="345" />
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/7/nativefiletypeviewer-fileiconimageconverter-convert-a-filename-to-the-file-system-icon/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
