0

I want to add programmatycally an image from my resources folder. For that, i have an object MEssage with 3 parameters :

 public class Message
{
    private System.Drawing.Image image;
    private string stringMember;
    private string nullMember;
    public Message(System.Drawing.Image i, string str1, string str2)
    {
        image = i;
        stringMember = str1;
        nullMember = str2;
    }
    public System.Drawing.Image MonImage
    {
        get { return image; }
    }
    public string StringMember
    {
        get { return stringMember; }
    }
    public string NullMember
    {
        get { return nullMember; }
    }
}

then i do that in the main :

 System.Drawing.Image myImage = WpfApp3.Properties.Resources.stan;
        List<Message> items = new List<Message>();
        items.Add(new Message(myImage, "Test", null));
        DataGrid.ItemsSource = items;

Here the result ... : enter image description here

Any ideas ? thanks !

simsim
  • 49
  • 1
  • 7
  • 1
    Do not use `System.Drawing.Image`. It is part of WinForms and shouldn't be used in a WPF application. See e.g. [this answer](https://stackoverflow.com/a/22957974/1136211) or [this one](https://stackoverflow.com/a/15008178/1136211) for more information. – Clemens Sep 29 '18 at 16:09
  • I just tested and now I have the same result, but with the "pack://application:,,,/Resources/copyPaste.png" text inside my cell. Why is the image not displayed? thank's a lot for your help ;) – simsim Sep 29 '18 at 20:40
  • Use a DataGridTemplateColumn with an Image element in its CellTemplate. – Clemens Sep 29 '18 at 21:17

0 Answers0