Home > DeveloperSection > Forums > How to bind the local image in datagrid using wpf?
marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    August-08-2013 7:43 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 4176  View(s)
Rate this:

I have a datagrid in wpf and I want to show an image in image column. How to do the task?

Please provide a demo if possible.

Any help will be appreciated.



shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    August-09-2013 7:00 AM

Hi!
You can use the below lines of code to show an image in image column of datagrid.
In window.xaml code :-
        <DataGrid AutoGenerateColumns="False" Margin="12" Name="dataGrid1">
            <DataGrid.Columns>
                <DataGridTemplateColumn>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="{Binding ImageFilePath}" Width="50" Height="50" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
In window.xaml.cs code :-
public class imageBinding
        {
            public BitmapImage ImageFilePath { get; set; }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i <= 20; i++)
            {
                dataGrid1.Items.Add(new imageBinding { ImageFilePath = new BitmapImage(new Uri(@"Physical Image File Path           ")) });
            }
        }
thanks!


Don't want to miss updates? Please click the below button!

Follow MindStick