如何在里面创建一个带有GridView的ListView

时间:2013-01-21 13:44:51

标签: c# .net wpf listview gridview

我正在尝试将ListView项目放在我的ListView中,它与GridView对象分隔成列。

我不知道如何在列中添加新项目,并且网上没有那么多有用的教程。

这是ListView的XAML代码:

        <ListView Canvas.Left="200" Canvas.Top="68" Height="138" Name="listView1" Width="444">
        </ListView>

GridView是动态创建的:

    public MainWindow()
    {
        InitializeComponent();

        GridView grdView = new GridView();

        GridViewColumn nameColumn = new GridViewColumn();
        nameColumn.DisplayMemberBinding = new Binding("Time");
        nameColumn.Header = "Time";
        nameColumn.Width = 120;
        grdView.Columns.Add(nameColumn);

        GridViewColumn ageColumn = new GridViewColumn();
        ageColumn.DisplayMemberBinding = new Binding("Date");
        ageColumn.Header = "Date";
        ageColumn.Width = 120;
        grdView.Columns.Add(ageColumn);

        listView1.View = grdView;
    }

我想在ListView中添加一些项目,怎么做?

1 个答案:

答案 0 :(得分:1)

您需要将其绑定到某些数据

ItemsControl.ItemsSource Property