WPF可以添加datagrid图像列吗? [英] WPF add datagrid image column possible?
本文介绍了WPF可以添加datagrid图像列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用C#.Net 4.5,Visual Studio 2012 Ulti,WPF。
Using C#.Net 4.5, Visual Studio 2012 Ulti, WPF.
我有一些旧的win-forms代码,我想在这个新的WPF
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?
感谢帮助人们
推荐答案
看到这个答案:
<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中显示图像以datagrid列编程?
这篇关于WPF可以添加datagrid图像列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文