WPF列表绑定到ListView [英] WPF List binding to ListView

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

问题描述



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

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

  class 数据
{

// 使用cLR属性而不是依赖属性(不确定是否会导致
// 有任何问题)

私有列表< string> _pName;
      私有列表< string> _pNumber;

  公共 ' 列表'< string> '  PName
        {
            得到{return _pName; }
            设置{_pName =值; }
        }

        公共"  List< string> P号
        {
            获取 {返回 _pNumber; }
             set  {_pNumber =  value ; }
        }

// 通过某些函数调用相应地获取PName和PNumber中的数据 


我的XAML看起来像这样-

'<   listview     selectedvaluepath   ="    名称  ="  someName" 选择模式  ="    边距  ="   > 
'selectionchanged ="some_SelectionChanged" focusable ="False" fontweight ="Bold" tabindex ="4">
          
            '<   listview.view  > 
                '<   gridview  > 
                    '<   gridview.columns  > 
                        '<   gridview列   标题  ="  宽度  自动" / <   gridview列   标题  ="  宽度  自动" / <  /gridview.columns  > 
                '<  /gridview  > 
            '<  /listview.view  > 
       '<  /listview  >  


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

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

谢谢!!!

解决方案

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

someName.ItemsSource = Data.PNumber();

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

在您的listview定义中添加someName
ItemContainerStyle ="{StaticResource ItemContStyle}";
ItemsSource ="{Binding}";


参考:

< a href ="http://stackoverflow.com/questions/1927139/wpf-listview-databinding-to-generic-list-dynamically-filled-by-wcf-service"> http://stackoverflow.com/Questions/1927139/wpf-listview-databinding-to-generic-list-dynamicly-filled by-wcf-service</a> [< a href ="http://stackoverflow.com/questions/1927139/wpf- listview数据绑定到由wcf服务动态填充的通用列表" target ="_ blank" title ="New Window"> ^</a>]


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.

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 


My XAML looks like this -

'<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 !!

解决方案

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}";


refer:

<a href="http://stackoverflow.com/questions/1927139/wpf-listview-databinding-to-generic-list-dynamically-filled-by-wcf-service">http://stackoverflow.com/questions/1927139/wpf-listview-databinding-to-generic-list-dynamically-filled-by-wcf-service</a>[<a href="http://stackoverflow.com/questions/1927139/wpf-listview-databinding-to-generic-list-dynamically-filled-by-wcf-service" target="_blank" title="New Window">^</a>]


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

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