wpf - 从uri添加图片+文字 [英] wpf - add image + text from uri
本文介绍了wpf - 从uri添加图片+文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi guys
i想要将项目+图标添加到listview我试试这段代码:
private void b2_Click_1( object sender,RoutedEventArgs e)
{
ListViewItem myItem = new ListViewItem();
Image img = new Image();
img.Source = new BitmapImage( new Uri( pack:// application:,,, / Images / save.png));
myItem.Content = img;
ListView1.Items.Add(myItem);
}
和iconview中的图标添加。但如何在listview中添加textbox1.text + images ???
解决方案
ListViewItem = img + textblock?
你设置:myItem.Content = img;
如果你想要image + textblock,你必须为listview项创建datatemplate。
示例:
http:// www。 wpf-tutorial.com/listview-control/listview-data-binding-item-template/ [ ^ ]
使用图像和文本< listbox.itemtemplate >
< datatemplate >
< stackpanel orientation = 水平 >
< image source = / Images / save.png / >
< textblock text = {Binding FileName} / >
< / stackpanel >
< / datatemplate >
< / listbox.itemtemplate >
hi guys
i want to add item + icon to listview i try this code :
private void b2_Click_1(object sender, RoutedEventArgs e)
{
ListViewItem myItem = new ListViewItem();
Image img = new Image();
img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/save.png"));
myItem.Content = img;
ListView1.Items.Add(myItem);
}
and icon add in listview. but how can add textbox1.text + images in listview???
解决方案
ListViewItem = img + textblock?
you set: myItem.Content = img;
If you want image + textblock you have to create datatemplate for listview item.
Example:
http://www.wpf-tutorial.com/listview-control/listview-data-binding-item-template/[^]
define itemtemplate of the listbox with image and text<listbox.itemtemplate> <datatemplate> <stackpanel orientation="Horizontal"> <image source="/Images/save.png" /> <textblock text="{Binding FileName}" /> </stackpanel> </datatemplate> </listbox.itemtemplate>
这篇关于wpf - 从uri添加图片+文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文