How to bind the local image in datagrid using wpf?

Total Post:104

Points:728
WPF 
WPF
 6585  View(s)
Ratings:
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.

  1. Post:105

    Points:735
    Re: How to bind the local image in datagrid using wpf?

    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!

      Modified On Mar-30-2018 05:50:54 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.