将列表视图中的列表框绑定到数组 [英] Binding a listbox in listview to arrayist

查看:109
本文介绍了将列表视图中的列表框绑定到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


这可能是一个愚蠢的问题,但我是一个初学者,所以我不确定.我有3个列表,并在列表视图的3个不同的列表框中显示它们,如下所示:

Hi,
This might be a silly question but im a beginner so im not sure. I have 3 lists and i am displaying them on 3 different listboxes in a listview as follows:

public System.Collections.ArrayList name
       {
           get
           {
               return _name;
           }

       }
       public System.Collections.ArrayList path
       {
           get
       {
               return _path;
       }

       }
       public System.Collections.ArrayList size
       {
           get
           {
               return _size;
           }

       }



对应的xml:



Corresponding xml:

<pre lang="HTML"><listview.view>
                    <gridview>
                        <gridviewcolumn>
                            Width="270" 
                            Header="File Name">
                            <gridviewcolumn.celltemplate>
                                <datatemplate>
                                    <!--<listbox name="listbox_name" itemssource="{Binding s}" />-->
                                    <listbox itemssource="{Binding Path= name}" issynchronizedwithcurrentitem="True" />    
                                </datatemplate>
                            </gridviewcolumn.celltemplate>
                        </gridviewcolumn>
                        <gridviewcolumn>
                            Width="270" 
                            Header="File Path">
                            <gridviewcolumn.celltemplate>
                                <datatemplate>
                                    <!--<listbox name="listbox_path" itemssource="{Binding abcdf}" />-->
                                    <listbox itemssource="{Binding Path= path}" issynchronizedwithcurrentitem="True" />
                                </datatemplate>
                            </gridviewcolumn.celltemplate>
                        </gridviewcolumn>
                        <gridviewcolumn>
                            Width="200" 
                            Header="File Size">
                            <gridviewcolumn.celltemplate>
                                <datatemplate>
                                    <!--<listbox name="listbox_size" />-->
                                    <listbox itemssource="{Binding Path= size}" issynchronizedwithcurrentitem="True" />
                                </datatemplate>
                            </gridviewcolumn.celltemplate>
                        </gridviewcolumn>
                    </gridview>
                </listview.view>



但是我看不到任何结果!我认为我犯了一个基本错误,无法弄清楚:(请帮助我!谢谢:)



But i dont see any result! I think im making a basic mistake, not able to figure it out :( Please help me! thanks :)

推荐答案

绑定绑定集合时请亲切检查数据是否存在..
Kindly check the data is there while binding your collection..


您是否设置了如果在窗口的类中声明了属性,则可以将DataContext设置为窗口.只需添加以下行:

If you declared the properties in the window''s class, you can set the DataContext to the window. Just add this line:

DataContext = this;

到窗口类的构造函数.

但是,最好在另一个类中声明属性,然后将DataContext设置为该类.有关更多详细信息,请阅读有关 MVVM .

But, it is better to declare the properties in a different class and, set the DataContext to that class. For more details, read about MVVM.

另一个问题是集合的类型.如果将ArrayList替换为 ObservableCollection ,您的视图也会收到有关该集合的通知的更改.

Another issue is the type of the collection. If you replace the ArrayList with an ObservableCollection, your view also will be notified about the collection''s changes.


太好了!我是通过使用以下发布的解决方案来获得它的: http://www.switchonthecode. com/tutorials/wpf-tutorial-using-the-listview-part-1 [
Great! i got it by using the solution posted here: http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1[^]


这篇关于将列表视图中的列表框绑定到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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