WPF数据绑定-将List绑定到ListView [英] WPF data binding - binding List to ListView

查看:1339
本文介绍了WPF数据绑定-将List绑定到ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试填充List< string>在ListView中,但面临的问题根本无法填充数据.

下面给出我要遵循的步骤,请提供帮助.


进行大量搜索,但似乎不起作用.<< br模式=保持"/>

Hi,

I''m trying to populate the List<string> in ListView, but facing problem not at all able to populate the data.

Below giving the steps that I''m following please help.


Search on this a lot but seems its not working.<<br mode="hold" />

class Data
{
 
//using cLR properties and not a dependency property (not sure whether that causing 
//any problem)

private List<string> _pName;
      private List<string> _pNumber;
 
  public' List'<string>' PName
        {
            get { return _pName; }
            set { _pName= value; }
        }
 
        public' List<string> PNumber
        {
            get { return _pNumber; }
            set { _pNumber= value; }
        }
 
//Getting data in PName and PNumber accordingly by some function call





<listview selectedvaluepath="Value" name="someName" selectionmode="Single" margin="263,35,12,50">
selectionchanged="some_SelectionChanged" focusable="False" fontweight="Bold" tabindex="4">
          
            <listview.view>
                <gridview>
                    <gridview.columns>
                       <gridviewcolumn header="Person Number" width="Auto" />
                       <gridviewcolumn header="Person Name" width="Auto" />
                     </gridview.columns>
                </gridview>
            </listview.view>
        </listview>




搜索很多,但似乎不起作用.

如果您需要更多详细信息,请告诉我.

谢谢!!!




Search on this a lot but seems its not working.

Please let me know if you need any more details.

Thanks !!

推荐答案

您只是没有填充列表视图
示例操作方法:

someName.ItemsSource = Data.PNumber();

您可以放入someName.ItemSource =//这样的特殊方法,如GetYourPNumbers()

在您的listview定义中添加someName
ItemContainerStyle ="{StaticResource ItemContStyle}";
ItemsSource ="{Binding}";
You just didn''t populate your listview
Example how to do it:

someName.ItemsSource = Data.PNumber();

You can put into the someName.ItemSource=// a special method like GetYourPNumbers()

Add to your definition of the listview someName
ItemContainerStyle="{StaticResource ItemContStyle}";
ItemsSource="{Binding}";


这篇关于WPF数据绑定-将List绑定到ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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