0

I have a problem displaying an image in WPF. The problem is that I add the image into the Grid and I can not actually see the image. I can see the place where the image is, but not the image itself (check the image below): enter image description here

Here is my code:

View:

<DataGridTemplateColumn Header="Image" Width="SizeToCells" IsReadOnly="True" Visibility="Visible">
  <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
      <Image Height="25" Width="50" Source="{Binding Path=ImageArticle}" />
    </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Here I take the path and add it:

ContinueArticle ca = new ContinueArticle();
string ImagePath = Environment.CurrentDirectory + @"C:\iClipIT\Thumbs\" + ClipID;
ca.ImageArticle = ImagePath;
atlist.Add(ca);

And here I create the object and the getters and setters:

public static readonly DependencyProperty ArticleImageProperty
    = DependencyProperty.Register("ArticleImage", typeof(string), typeof(ContinueArticle));

public string ImageArticle
{
    get
    {
        return (string)GetValue(ArticleImageProperty);
    }
    set
    {
        SetValue(ArticleImageProperty, value);
    }
}

Any clue what I'm doing wrong? I read a lot about this and I can't find the problem.

Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
SomeAnonymousPerson
  • 3,173
  • 1
  • 21
  • 22
  • 2
    `Environment.CurrentDirectory + @"C:\iClipIT\Thumbs\"` doesn't make sense. It should probably be `string ImagePath = @"C:\iClipIT\Thumbs\" + ClipID;` – Clemens May 09 '16 at 07:06
  • 2
    Besides that it isn't clear why `ImageArticle` is a dependency property. It seems to be a view model property, and the source but not the target of a binding. Usually view models don't (need to) have dependency properties. – Clemens May 09 '16 at 07:12
  • Bind a bitmap property from your viewModel, u dont need a Dependency property. Y hv u created "ArticleImageProperty"? – Akanksha Gaur May 09 '16 at 07:34
  • Does your column contains same image for all cells? – Akanksha Gaur May 09 '16 at 07:35
  • I just found out that was exactly the problem. The Path was incorrect so it was creating the spot but not actually adding the image. As I changed it, it works perfectly! Thanks!! – SomeAnonymousPerson May 09 '16 at 08:10
  • Possible duplicate of [Add a Image in the DataGridTemplateColumn](http://stackoverflow.com/questions/14432313/add-a-image-in-the-datagridtemplatecolumn) – Kylo Ren May 09 '16 at 08:53

0 Answers0