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

  • Home
  • SEARCH
  • 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 9170813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:04:44+00:00 2026-06-17T16:04:44+00:00

The following xaml code binds the Image with the datagrid template column. <DataGridTemplateColumn Header=>

  • 0

The following xaml code binds the “Image” with the datagrid template column.

     <DataGridTemplateColumn Header="">

       <DataGridTemplateColumn.CellTemplate>

           <DataTemplate>

                <Image Source="{Binding Path=Image}" Height="16" Width="16" VerticalAlignment="Top" />

             </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>

   The same thing need to be done in codebehind (c# code)  

       DataGridTemplateColumn im = new DataGridTemplateColumn();
       im.Header = "";
       Binding items1 = new Binding();

this is what i have Tried…. how to bind the datagridtemplate column to a image ??

  • 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-17T16:04:44+00:00Added an answer on June 17, 2026 at 4:04 pm

    Here is the code to add a DataGridTemplateColumn programatically.

    http://social.msdn.microsoft.com/Forums/en/wpf/thread/df77a277-91d4-41f1-a42a-0fa02a443ff4

    DataGridTemplateColumn imgColumn = new DataGridTemplateColumn();
    imgColumn.Header = "Image";
    
    FrameworkElementFactory imageFactory = new FrameworkElementFactory(typeof(Image));
    imageFactory.SetBinding(Image.SourceProperty, new Binding("ImgPath"));
    
    DataTemplate dataTemplate = new DataTemplate();
    dataTemplate.VisualTree = imageFactory;
    
    imgColumn.CellTemplate = dataTemplate;
    
    DGImages.Columns.Add(imgColumn);
    

    I have also added the source code of the sample app that I created. Hope it helps.

    MainWindow.xaml file

    <Window x:Class="StackOverflow.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
    <DataGrid Name="DGImages" AutoGenerateColumns="False">
    <DataGrid.Columns>
    <DataGridTextColumn Header="Image Desc" Binding="{Binding ImgDesc}"></DataGridTextColumn>
    </DataGrid.Columns>
    </DataGrid>
    </Grid>
    </Window>
    

    MainWindow.xaml.cs file

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Collections.ObjectModel;
    
    namespace StackOverflow
    {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
    private ObservableCollection<SampleClass> imgList = null;
    
    public MainWindow()
    {
    InitializeComponent();
    imgList = new ObservableCollection<SampleClass>();
    imgList.Add(new SampleClass() { ImgDesc = "First Image", ImgPath = @"/Images/MyImage.jpg" });
    
    DataGridTemplateColumn imgColumn = new DataGridTemplateColumn();
    imgColumn.Header = "Image";
    
    FrameworkElementFactory imageFactory = new FrameworkElementFactory(typeof(Image));
    imageFactory.SetBinding(Image.SourceProperty, new Binding("ImgPath"));
    
    DataTemplate dataTemplate = new DataTemplate();
    dataTemplate.VisualTree = imageFactory;
    
    imgColumn.CellTemplate = dataTemplate;
    
    DGImages.Columns.Add(imgColumn);
    
    this.DGImages.ItemsSource = imgList;
    }
    }
    }
    

    SampleClass.cs file

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    
    namespace StackOverflow
    {
    public class SampleClass : INotifyPropertyChanged
    {
    private string _ImgDesc;
    
    public string ImgDesc
    {
    get { return _ImgDesc; }
    set
    {
    _ImgDesc = value;
    OnPropertyChanged("ImgDesc");
    }
    }
    
    private string _ImgPath;
    
    public string ImgPath
    {
    get { return _ImgPath; }
    set
    {
    _ImgPath = value;
    OnPropertyChanged("ImgPath");
    }
    }
    
    public event PropertyChangedEventHandler PropertyChanged;
    
    public void OnPropertyChanged(string propertyName)
    {
    if (PropertyChanged != null)
    {
    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
    }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following XAML: <ComboBox Name=groupComboBox ItemsSource={Binding Path=MyServiceMap.Groups} DisplayMemberPath={Binding Name}/> In the code
I have the following XAML: <Window.Resources> <myApp:ImageDisplayConvertor x:Key=ImageDisplayConvertor /> </Window.Resources> <DataGridTemplateColumn Header=Icon> <DataGridTemplateColumn.CellTemplate >
I am binding a listbox with contacts address using following xaml code <ListBox Name=ContactResultsDataLINQ
I have the following code which Binds to properties within a ToolTip DataTemplate: <Window
I have a following XAML: <DataGrid Name=nodeDataGrid ItemsSource={Binding NodeList} AutoGenerateColumns=False RowBackground=White AlternatingRowBackground=AliceBlue Grid.Column=1 HorizontalAlignment=Stretch
I have the following working XAML code that basically binds a couple of properties
The following xaml code works: <Window x:Class=DerivedTemplateBug.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:DerivedTemplateBug Title=Window1 Height=300 Width=300> <Button>
I have the following XAML code: <phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible=True IsMenuEnabled=False x:Name=PageBar> <shell:ApplicationBarIconButton IconUri=/Assets/Icons/appbar.questionmark.rest.png Text=Help
I am NEW to WPF. I have the following XAML code: </Window> ... <Canvas>
I have the following code: <Window x:Class=kkk.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <Window.Resources> <Style

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.