【问题标题】:c# picture in to a datagridview from an URL from internet [closed]c#图片从来自互联网的URL到datagridview [关闭]
【发布时间】:2018-12-18 12:43:32
【问题描述】:

我正在做一个项目,我需要通过 Internet 的 URL 将图片放入 datagridview 中。我不知道该怎么做?有谁知道怎么做。我正在做的项目是在 c# WPF 中。我使用的是 mysql 数据库。

【问题讨论】:

标签: c# mysql wpf


【解决方案1】:

您可以使用 modelDataGridTemplateColumn 并执行以下操作:

       <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;
    }
}

图片模型

public class Picture
{
    public Picture(string path, string name)
    {
        Path = path;
        Name = name;
    }
    public string Path { get; set; }

    public string Name { get; set; }
}

【讨论】:

  • 谢谢它的工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-21
  • 1970-01-01
  • 1970-01-01
  • 2014-09-14
  • 2011-07-03
  • 2020-08-02
相关资源
最近更新 更多