title: Bind datatemplate image to an attribute of custom object in WPF
body: <p>I have a collection
  <code>private ObservableCollection&lt;ImageData&gt; imageDataList = new ObservableCollection&lt;ImageData&gt;();</code> where ImageData is a custom object. It has an attribute called <code>fileName</code> a string that stores full path of an image file. In my XAML code, I have a listbox with datatemplate as the following.</p>
  
  <pre><code>&lt;ListBox Name="listBox_ImageList" Grid.ColumnSpan="3" Grid.Row="2" SelectionChanged="listBox_ImageList_SelectionChanged"&gt;
          &lt;ListBox.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;VirtualizingStackPanel Orientation="Horizontal" /&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ListBox.ItemsPanel&gt;
  
          &lt;ListBox.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Image Source="{Binding fileName}" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox, AncestorLevel=1}, Path=ActualHeight}"/&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListBox.ItemTemplate&gt;
      &lt;/ListBox&gt;
  </code></pre>
  
  <p>After populating <code>ImagaData</code> objects into <code>imageDataList</code>, I set <code>this.listBox_ImageList.ItemsSource = imageDataList;</code></p>
  
  <p>However, when I run it, I don't see any images. Can you please tell me how to databind properly to a string member of an object to WPF image source?</p>