Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6176681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:08:38+00:00 2026-05-24T00:08:38+00:00

I have a list of objects. Each object has a property named ext that

  • 0

I have a list of objects.
Each object has a property named “ext” that represents the file type. (PDF, CSV, etc.)
Programmatically before binding the itemsource of the datagrid to the collection of objects, I’m dynamically creating the datagrid columns using datagridtemplatecolumn objects.

I have a DataTemplate resource that is basically an image:

<DataTemplate x:Key="imageThumb">
        <Image x:Name="docImage" Width="25" Height="25" Source="/MyApp;component/images/pdf-icon.png">
            <Image.Effect>
                <DropShadowEffect ShadowDepth="1" BlurRadius="1" Opacity="0.5"/>
            </Image.Effect>
        </Image>
    </DataTemplate>

Then in my code behind while dynamically creating the datagrid template columns:

DataTemplate imageTemplate = (DataTemplate)this.Resources["imageThumb"];

DataGridTemplateColumn docType = new DataGridTemplateColumn();
docType.Header = "Doc Type";
docType.CellTemplate = imageTemplate;
targetDataGrid.Columns.Add(docType);

When I simply set this as the cell template of the datagridtemplate column all is well but obviously every single row has a PDF icon in the column.
I’m wanting to dynamically change the source path of this Image” based on the extension property of the object that is bound to the datagrid row.

Is there any way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:08:39+00:00Added an answer on May 24, 2026 at 12:08 am

    Grab the code for the StringToObjectConverter from this blog Yet another blog about IValueConverter

    In your Xaml resources set up your set of known icon images in a StringToObjectConverter like this:

            <local:StringToObjectConverter x:Key="DocTypeToBitmap">
                 <ResourceDictionary>
                     <BitmapImage x:Key="pdf" UriSource="/MyApp;component/images/pdf-icon.png" />
                     <!-- Other BitmapImages here -->
                     <BitmapImage x:Key="__default__" UriSource="/MyApp;component/images/unknown-icon.png" /> 
                </ResourceDictionary>
             </local:StringToObjectConverter>
    

    (You could of course fill this list of BitmapImages programmatically if you prefer).

    Now you can use this converter with binding in you

    <DataTemplate x:Key="imageThumb">
        <Image x:Name="docImage" Width="25" Height="25" Source="{Binding docType, Converter={StaticResource DocTypeToBitmap}}"> 
            <Image.Effect>
                <DropShadowEffect ShadowDepth="1" BlurRadius="1" Opacity="0.5"/>            
            </Image.Effect>
        </Image>
    </DataTemplate>
    

    Now the image will track with changes to docType dynamically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of objects, where each object has a boolean property named
I have a list of objects. Each object has an integer quantity and a
Say I have a List of objects, and the object has a string property.
I have a ObservableCollection of Patient objects. Each Patient object has a Name property,
I have one class that has a list of objects of Daemon type. class
I have a List, it has Foo objects, and each Foo has a start
I have a list of objects and each and every object in the list
I have two lists of objects. Each list is already sorted by a property
I have a ListBox that is bound to a list of CustomerViewModel-objects, that each
I have a list of objects (of type 'TrackedSet') that is data bound to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.