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 9163185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:23:07+00:00 2026-06-17T14:23:07+00:00

BitmapImage im = new BitmapImage(); string path1 = @C:\abc.png; im.UriSource=new Uri(path1); DataGridTemplateColumn one =

  • 0
BitmapImage im = new BitmapImage();

string path1 = @"C:\abc.png";

im.UriSource=new Uri(path1);


DataGridTemplateColumn one = new DataGridTemplateColumn();

this.dataGrid1.Columns.Add(one);

Now i have to add the BitmapImage im in the datagridTemplateColumn.

How to add Image in the column??

  • 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-06-17T14:23:08+00:00Added an answer on June 17, 2026 at 2:23 pm

    Working with control templates in code is hard.
    In WPF the standard and effective way is to create your template layout in XAML. And then if you need to pass any data to your controls you use Data Binding. You shouldn’t normally need to construct templates in code except for rare circumstances.

    To get the same effect you intended above using XAML you write:

        <DataGrid x:Name="dataGrid1">
            <DataGrid.Columns>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="file:///C:\abc.png" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    

    If the image path has to be dynamic for every grid row you can modify it like this:

        <DataGrid x:Name="dataGrid1" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="{Binding ImageFilePath}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    

    and here’s an example code behind for populating the grid with some data:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
    
            List<MyDataObject> list = new List<MyDataObject>();
            list.Add(new MyDataObject() { ImageFilePath = new Uri("file:///c:\\abc.png") });
            list.Add(new MyDataObject() { ImageFilePath = new Uri("file:///c:\\def.png") });
            dataGrid1.ItemsSource = list;
        }
    }
    
    public class MyDataObject
    {
        public Uri ImageFilePath { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used private BitmapImage byteArrayToImage(byte[] byteArrayIn) { try { MemoryStream stream = new MemoryStream();
I use this code to populate WPF Image Control. string pathToImage = System.IO.Path.Combine(Settings.ContentFolderPath, file);
What I add a Image.Source I have to type the following: playIcon.Source = new
[DllImport(Project1.dll)] unsafe static extern void CallFu(string OpenFile, string SaveFile); This is dll on C++
I'm using BitmapImage as Source to an Image control in WPF. BitmapImage bi =
What's the best way to print a BitmapImage? I come from a background in
I need to display favicon.ico files fetched from arbitrary Web Sites as a BitmapImage
I have a bitmap image context and want to let this appear blurry. So
So I think I'm doing something pretty basic. I know why this doesn't work,
I am storing a PNG as an embedded resource in an assembly. From within

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.