<p>I'm trying to bind a list of custom objects to a WPF Image like this:</p>

<pre><code>&lt;Image&gt;
    &lt;Image.Source&gt;
        &lt;BitmapImage UriSource="{Binding Path=ImagePath}" /&gt;
    &lt;/Image.Source&gt;
&lt;/Image&gt;
</code></pre>

<p>But it doesn't work. This is the error I'm getting:</p>

<p><em>"Property 'UriSource' or property 'StreamSource' must be set."</em></p>

<p>What am I missing?</p>

[{'answer_id': 20617, 'author': 'Dale Ragan', 'author_id': 1117, 'author_profile': 'https://Stackoverflow.com/users/1117', 'pm_score': 3, 'selected': False, 'text': '<p>You need to have an implementation of <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx" rel="nofollow noreferrer">IValueConverter</a> interface that converts the uri into an image.  Your Convert implementation of IValueConverter will look something like this:</p>\n\n<pre><code>BitmapImage image = new BitmapImage();\nimage.BeginInit();\nimage.UriSource = new Uri(value as string);\nimage.EndInit();\n\nreturn image;\n</code></pre>\n\n<p>Then you will need to use the converter in your binding:</p>\n\n<pre><code>&lt;Image&gt;\n    &lt;Image.Source&gt;\n        &lt;BitmapImage UriSource="{Binding Path=ImagePath, Converter=...}" /&gt;\n    &lt;/Image.Source&gt;\n&lt;/Image&gt;\n</code></pre>\n'}, {'answer_id': 20648, 'author': 'palehorse', 'author_id': 312, 'author_profile': 'https://Stackoverflow.com/users/312', 'pm_score': 4, 'selected': False, 'text': '<p>You can also simply set the Source attribute rather than using the child elements.  To do this your class needs to return the image as a Bitmap Image.  Here is an example of one way I\'ve done it</p>\n\n<pre><code>&lt;Image Width="90" Height="90" \n       Source="{Binding Path=ImageSource}"\n       Margin="0,0,0,5" /&gt;\n</code></pre>\n\n<p>And the class property is simply this</p>\n\n<pre><code>public object ImageSource {\n    get {\n        BitmapImage image = new BitmapImage();\n\n        try {\n            image.BeginInit();\n            image.CacheOption = BitmapCacheOption.OnLoad;\n            image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;\n            image.UriSource = new Uri( FullPath, UriKind.Absolute );\n            image.EndInit();\n        }\n        catch{\n            return DependencyProperty.UnsetValue;\n        }\n\n        return image;\n    }\n}\n</code></pre>\n\n<p>I suppose it may be a little more work than the value converter, but it is another option.</p>\n'}, {'answer_id': 20737, 'author': 'Brian Leahy', 'author_id': 580, 'author_profile': 'https://Stackoverflow.com/users/580', 'pm_score': 7, 'selected': True, 'text': '<p>WPF has built-in converters for certain types. If you bind the Image\'s <code>Source</code> property to a <code>string</code> or <code>Uri</code> value, under the hood WPF will use an <a href="https://msdn.microsoft.com/en-us/library/system.windows.media.imagesourceconverter(v=vs.110).aspx" rel="noreferrer">ImageSourceConverter</a> to convert the value to an <code>ImageSource</code>.</p>\n\n<p>So</p>\n\n<pre><code>&lt;Image Source="{Binding ImageSource}"/&gt;\n</code></pre>\n\n<p>would work if the ImageSource property was a string representation of a valid URI to an image.</p>\n\n<p>You can of course roll your own Binding converter:</p>\n\n<pre class="lang-cs prettyprint-override"><code>public class ImageConverter : IValueConverter\n{\n    public object Convert(\n        object value, Type targetType, object parameter, CultureInfo culture)\n    {\n        return new BitmapImage(new Uri(value.ToString()));\n    }\n\n    public object ConvertBack(\n        object value, Type targetType, object parameter, CultureInfo culture)\n    {\n        throw new NotSupportedException();\n    }\n}\n</code></pre>\n\n<p>and use it like this:</p>\n\n<pre><code>&lt;Image Source="{Binding ImageSource, Converter={StaticResource ImageConverter}}"/&gt;\n</code></pre>\n'}, {'answer_id': 862583, 'author': 'Drew Noakes', 'author_id': 24874, 'author_profile': 'https://Stackoverflow.com/users/24874', 'pm_score': 4, 'selected': False, 'text': '<p><a href="http://www.infosysblogs.com/microsoft/2008/04/wpf_binding_to_image_control.html" rel="noreferrer">This article</a> by Atul Gupta has  sample code that covers several scenarios:</p>\n\n<ol>\n<li>Regular resource image binding to Source property in XAML</li>\n<li>Binding resource image, but from code behind</li>\n<li>Binding resource image in code behind by using Application.GetResourceStream</li>\n<li>Loading image from file path via memory stream (same is applicable when loading blog image data from database)</li>\n<li>Loading image from file path, but by using binding to a file path Property</li>\n<li>Binding image data to a user control which internally has image control via dependency property</li>\n<li>Same as point 5, but also ensuring that the file doesn\'t get\'s locked on hard-disk</li>\n</ol>\n'}, {'answer_id': 13895496, 'author': 'Luis Cantero', 'author_id': 569998, 'author_profile': 'https://Stackoverflow.com/users/569998', 'pm_score': 3, 'selected': False, 'text': '<p>The problem with the answer that was chosen here is that when navigating back and forth, the converter will get triggered every time the page is shown.</p>\n\n<p>This causes new file handles to be created continuously and will block any attempt to delete the file because it is still in use. This can be verified by using Process Explorer.</p>\n\n<p>If the image file might be deleted at some point, a converter such as this might be used:\n<a href="https://stackoverflow.com/questions/3427034/using-xaml-to-bind-to-a-system-drawing-image-into-a-system-windows-image-control">using XAML to bind to a System.Drawing.Image into a System.Windows.Image control</a></p>\n\n<p>The disadvantage with this memory stream method is that the image(s) get loaded and decoded every time and no caching can take place:\n"To prevent images from being decoded more than once, assign the Image.Source property from an Uri rather than using memory streams"\nSource: "Performance tips for Windows Store apps using XAML"</p>\n\n<p>To solve the performance issue, the repository pattern can be used to provide a caching layer. The caching could take place in memory, which may cause memory issues, or as thumbnail files that reside in a temp folder that can be cleared when the app exits.</p>\n'}, {'answer_id': 19480862, 'author': 'Karthik Krishna Baiju', 'author_id': 2608383, 'author_profile': 'https://Stackoverflow.com/users/2608383', 'pm_score': 3, 'selected': False, 'text': '<p>you may use</p>\n\n<blockquote>\n  <p>ImageSourceConverter class</p>\n</blockquote>\n\n<p>to get what you want</p>\n\n<pre><code>    img1.Source = (ImageSource)new ImageSourceConverter().ConvertFromString("/Assets/check.png");\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/20586', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/373/']