c# - wpf listView带图像的项目 - 帮助 [英] c# - wpf listView Items with image - help

查看:114
本文介绍了c# - wpf listView带图像的项目 - 帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友



i在表单中有一个列表视图,但在wpf中没有图像列表用于包含图像的项目,只是添加没有图像的文本项目,在窗体中应用程序可以添加带有图像的项目,如下代码:



listview1.items.add(textbox1.text,0);



可以帮助我添加像wpf形式的图像项目,如图像?????



http://oi58.tinypic.com/mud5kz.jpg [ ^ ]

解决方案

您需要创建一个数据模板,然后设置列表视图的项模板属性,如下所示:



< window.resources>
< datatemplate x:key =ImageCellxmlns:x =#unknown>
< stackpanel orientation =水平>
< image source ={Binding PlayerCardImages}width =200height =200stretch =Filltooltip =Add tooltip/>
< / stackpanel>
< / datatemplate>
< /window.resources>

< stackpanel orientation =Vertical>
< label content =玩家卡/>
< listview name =lvwTitlesitemssource ={Binding}>
IsSynchronizedWithCurrentItem =True
SelectionMode =SingleItemTemplate ={StaticResource ImageCell}Height =59>
< / listview>
< / stackpanel>





项目模板中的堆栈面板中可以包含任何内容(在合理范围内)。


hi friend

i have one list view in form,but in wpf dont have imagelist for use items with image, and just add text items without image, in windowform application can add items with image like this code :

listview1.items.add(textbox1.text, 0);

can help me to add items with image in wpf form like this image?????

http://oi58.tinypic.com/mud5kz.jpg[^]

解决方案

You will need to create a data template, and then set the item template property of the list view, like this:

<window.resources>
 <datatemplate x:key="ImageCell" xmlns:x="#unknown">
        <stackpanel orientation="Horizontal">
            <image source="{Binding PlayerCardImages}" width="200" height="200" stretch="Fill" tooltip="Add tooltip" />
        </stackpanel>
    </datatemplate>
</window.resources>

 <stackpanel orientation="Vertical">
 <label content="Player Cards" />
        <listview name="lvwTitles" itemssource="{Binding}">
 IsSynchronizedWithCurrentItem="True" 
 SelectionMode="Single" ItemTemplate="{StaticResource ImageCell}" Height="59">
        </listview>
 </stackpanel>



The stack panel in the item template can have anything in it (within reason).


这篇关于c# - wpf listView带图像的项目 - 帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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