Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2320
Dynamically change and Image.Source for an unbound column
posted

I have a grid, that needs to have an image displayed in a column.  This image will be different for each row depending on several other columns in the row. 

Here is my xaml for the unbound column

<igGrid:UnboundColumn Key="Status" HeaderText=" " Width="30">
    <igGrid:UnboundColumn.ItemTemplate>
        <DataTemplate >
            <Image Stretch="Fill" Width="20" Source="" />
        </DataTemplate>
    </igGrid:UnboundColumn.ItemTemplate>
</igGrid:UnboundColumn>

I'm not sure I got the xaml correct but if I hardcode Source property, everything displays properly.

Is there anyway in the InitializeRow function of the grid that I could set the source property on the image for that row?

Any help would be greatly appreciated.

 

Parents
No Data
Reply
  • 2320
    posted

    I figured out how to get this working so I figured I'd post for anyone else who ever is trying to do this.

    I changed my xaml for the image to

    <igGrid:ImageColumn Key="Status" HeaderText=" "  />

    I then added a public property to the object I was binding to.  In our case, its a POCO object that mimics a DataRow object.  So in my datarow object, i put this property in it.

    public System.Windows.Media.Imaging.BitmapImage Status
    {
        get
        {               
            Uri uri = null;

             if (this.StatIncomplete || this.StatRejected)
                 uri = new Uri(@"/Modules.Common;component/Images/fail.png", UriKind.Relative);
             else if (this.StatOutdated)
                 uri = new Uri(@"/Modules.Common;component/Images/warning.png", UriKind.Relative);
             else if (this.StatTestData)
                 uri = new Uri(@"/Modules.Common;component/Images/new_16.png", UriKind.Relative);               
                   
                    System.Windows.Media.Imaging.BitmapImage image = new System.Windows.Media.Imaging.BitmapImage(uri);               
                    return (image);
                }
            }

     

    I'd still like to know how to access it from the InitializeRow if anyone has any ideas.

Children