DataGrid how bind a column with key resource

Apr 7, 2009 at 12:02 PM
Hi,
i need help about datagrid.

I have a DataGrid bounded(via code) with a myclass that has 2 columns.
in the 1st column there is a description and in the 2nd column there is a string that represent a resource key of an image.
How I can create a column that show the image reading the resource key?


 

 

<my:DataGrid Name="dbGrid" AutoGenerateColumns="False" DataContext="{ Binding }">
<my:DataGrid.Columns >
    <my:DataGridTextColumn TextBlock.TextAlignment="Center" Binding="{Binding Path=Description}" Header="Image Description" />
        <my:DataGridTemplateColumn>
                    <my:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Name="Pic"  Source={Binding ?Book?}> </Image>
                        </DataTemplate>
                     </my:DataGridTemplateColumn.CellTemplate>
          </my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>

 

 

 

 

 

 

 

ResourceFile
<
Image x:Key="Book" Source="Images/Text.png" />

 

 

 


 

 

Apr 7, 2009 at 12:17 PM
I would imagine that you can bind the <Image/> Source to the class' property, using a converter that returns an image object when given a resource path as input. (FindResource is your friend.)
Apr 7, 2009 at 12:54 PM
have you an example please?
Coordinator
Apr 7, 2009 at 9:48 PM
Try making your resource an ImageSource rather than an Image.  Then use StaticResource rather than Binding:

ResourceFile
<
ImageSource x:Key="Book">"Images/Text.png"<ImageSource/>



<Image Name="Pic"  Source={StaticResource Book}> </Image>