I'm working on a project where I need a picture in to a datagridview by an URL form internet. I can't find out how to do it? Does anyone know how do do it. the project im makeing is in c# WPF. and im useing a mysql database.
Asked
Active
Viewed 45 times
1 Answers
0
You could use a model
and a DataGridTemplateColumn
and do something like this:
<DataGrid Name="DataGrid">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Path}" Height="100"></Image>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Name}"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
MainWindow.cs
public partial class MainWindow : Window
{
public List<Picture> Pictures { get; set; }
public MainWindow()
{
InitializeComponent();
Pictures = new List<Picture>()
{
new Picture("https://images.askmen.com/1080x540/2017/01/06-044621-the_pitfalls_of_dating_a_married_woman.jpg", "Girl 1"),
new Picture("https://images.pexels.com/photos/733872/pexels-photo-733872.jpeg?cs=srgb&dl=beautiful-blur-blurred-background-733872.jpg&fm=jpg", "Girl 2")
};
DataGrid.ItemsSource = Pictures;
}
}
Picture Model
public class Picture
{
public Picture(string path, string name)
{
Path = path;
Name = name;
}
public string Path { get; set; }
public string Name { get; set; }
}