在WPF的ListView多列在设计时 [英] Multicolumn listview in WPF at design time

查看:635
本文介绍了在WPF的ListView多列在设计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听起来哑巴这里,但我想要做的事情真的很简单。在设计时,我想将列添加到ListView控件和一些数据添加到它。我需要在列表视图中的每一列添加组合框。我无法找到的东西是从哪里提在ListViewItem的列数。任何帮助AP preciated家伙。

 < ListView控件IsSynchronizedWithCurrentItem =真保证金=8,68,304,188
      了borderThickness =2,2,2,2>
 < ListView.View>
   <&GridView的GT;
    < GridViewColumn WIDTH =150标题=列1/>
    < GridViewColumn WIDTH =150标题=列2/>
   < / GridView的>
 < /ListView.View>
 < ListViewItem的>
 < / ListViewItem的>
< /&的ListView GT;


解决方案

在ListViewItem每一列基于GridView的定义渲染,所以列数没有真正的概念。你要做的就是将对象绑定到ListView的的ItemSource并从它创建listviewitems。因此,也有少数箍通过跳跃。

<一个href=\"http://www.wrox.com/WileyCDA/Section/Windows-$p$psentation-Foundation-WPF-Data-Binding-with-C-2005.id-305562.html\"相对=nofollow>这个链接对如何做一些简单的对象数据绑定的例子。这样做的好处是你有设计时结合的结构,如果你在DataContext设置/的ItemSource一个空的对象,而不是静态之一XAML大概可以重复使用运行时间。

如果你这样做是显示的例子,或者你只是要使用静态数据源,我会推荐使用的 XmlDataProvider 。然后,你会改变你的ListView是这样的,



&LT; ListView控件IsSynchronizedWithCurrentItem =真保证金=8,68,304,188
      了borderThickness =2,2,2,2>
 &LT; ListView.View>
   &LT; GridView控件>
    &LT; GridViewColumn WIDTH =150标题=列1的DisplayMemberPath ={结合的XPath = / A / B}/>
    &LT; GridViewColumn WIDTH =150标题=列2的DisplayMemberPath ={结合的XPath = / A / C/>
   &LT; / GridView控件>
 &LT; /ListView.View>
 &LT; ListViewItem的>
 &LT; / ListViewItem的>
&LT; /的ListView>

I might sound dumb here, but I want to do something really simple. At design time, I want to add columns to a listview control and add some data to it. I need to add combobox in each column of the listview. The thing I am not able to find is where to mention the column number in the listviewitem. Any help appreciated guys.

<ListView IsSynchronizedWithCurrentItem="True" Margin="8,68,304,188"  
      BorderThickness="2,2,2,2">
 <ListView.View>
   <GridView>
    <GridViewColumn Width="150" Header="Column1"/>
    <GridViewColumn Width="150" Header="Column2"/>
   </GridView>
 </ListView.View>
 <ListViewItem>                              
 </ListViewItem>            
</ListView>

解决方案

Each column in the listviewitem is rendered based on the GridView definition, so there is no real concept of column numbers. What you do is bind objects to the the listview's itemsource and it creates listviewitems from it. Thus, there are a few hoops to jump through.

This link has an example of how to do some simple object data binding. The advantage of this is what binding structure you have for design time can probably be reused for run-time if you set the datacontext/itemsource to an empty object instead of the static one in XAML.

If you're doing this to show examples or you just have a static data source that you want to use, I would recommend using the XmlDataProvider. Then you'd change your ListView to be like this,


<ListView IsSynchronizedWithCurrentItem="True" Margin="8,68,304,188"  
      BorderThickness="2,2,2,2">
 <ListView.View>
   <GridView>
    <GridViewColumn Width="150" Header="Column1" DisplayMemberPath="{Binding XPath=/A/B}"/>
    <GridViewColumn Width="150" Header="Column2" DisplayMemberPath="{Binding XPath=/A/C"/>
   </GridView>
 </ListView.View>
 <ListViewItem>                              
 </ListViewItem>            
</ListView>

这篇关于在WPF的ListView多列在设计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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