Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I might not properly understand your question but if i got it right: you want to display an image in some WPF control.</p> <p>1) Bind path to your image to the control (I used DataGrid): </p> <pre><code> &lt;DataGrid ItemsSource="{Binding Path=ImageCollection}" &lt;DataGrid.Columns&gt; &lt;DataGridTemplateColumn Header="Image"&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Image Width="40" Height="20" Source="{Binding FilePath, Converter={StaticResource ResourceKey=ImageConverter}}"/&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;/DataGrid&gt; </code></pre> <p>2) Create converter that converts FilePath to ImageSource (I found it somewhere in the Internet):</p> <pre><code> public class ImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var path = value as string; if (path == null) { return DependencyProperty.UnsetValue; } //create new stream and create bitmap frame var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); try { bitmapImage.StreamSource = new FileStream(path, FileMode.Open, FileAccess.Read); //load the image now so we can immediately dispose of the stream bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); //clean up the stream to avoid file access exceptions when attempting to delete images bitmapImage.StreamSource.Dispose(); return bitmapImage; } catch (Exception) { //do smth } } } </code></pre> <p>Hope, this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload