WPF添加数据网格图像列可能吗? [英] WPF add datagrid image column possible?

查看:20
本文介绍了WPF添加数据网格图像列可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 C#.Net 4.5、Visual Studio 2012 Ulti、WPF.

Using C#.Net 4.5, Visual Studio 2012 Ulti, WPF.

我想在这个新的 WPF 应用程序中执行一些旧的 win-forms 代码.

I've got some old win-forms code that i wanted to do in this new WPF app.

代码如下:

DataGridViewImageCell pNew = new DataGridViewImageCell();

ParetoGrid.Columns.Add(new DataGridViewImageColumn() { CellTemplate = pNew, FillWeight = 1, HeaderText = "pNew", Name = "pNew", Width = 30 });

ParetoGrid.Columns["pNew"].DisplayIndex = 18;

3 行代码添加一个可以处理图像的列.在 WPF 中,我看到它有点不同.我需要添加一个图像列"吗?还是 WPF 列支持图像?还是有另一种语法不同的 3 行解决方案?

3 lines of code to add a column that can handle images. In WPF I've seen its a bit different. Do i need to add an "image column"? or does WPF columns support images? or is there another 3 liner solution that is simply different syntax?

谢谢大家的帮助

推荐答案

看到这个答案:

WPF DataGrid 中的图像列

 <DataGridTemplateColumn Header="Image" Width="SizeToCells"
 IsReadOnly="True">
   <DataGridTemplateColumn.CellTemplate>
      <DataTemplate>
           <Image Source="{Binding Image}" />
      </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
 </DataGridTemplateColumn>

在代码之后添加一列:

DataGridTextColumn textColumn1 = new DataGridTextColumn();
textColumn1.Header = "Your header";
textColumn1.Binding = new Binding("YourBindingField");
dg.Columns.Add(textColumn1);

使用 DataGridTemplateColumn 添加自定义列请参阅:如何以编程方式在 wpf 数据网格列中显示图像?

Use DataGridTemplateColumn to add a custom column See: How do I show image in wpf datagrid column programmatically?

这篇关于WPF添加数据网格图像列可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆