如何在WPF c#中的2个数组的2列中填充listview

时间:2013-02-03 06:54:02

标签: c# wpf listview listviewitem

我有一个listview项目

(XAML)

<ListView Name="myListView" BorderThickness="2,2,2,2" Margin="12,27,428,12">
        <ListView.View>
            <GridView>
                <GridViewColumn Width="150" Header="Column1" DisplayMemberBinding="{Binding Test1}"/>
                <GridViewColumn Width="150" Header="Column2" DisplayMemberBinding="{Binding Test2}"/>
            </GridView>
        </ListView.View>
        <ListViewItem>
        </ListViewItem>
    </ListView>

并希望用2个不同的数组填充

string[] ApplicationNames
string[] ClassNames

但我很难这样做。有人能指出我正确的方向吗?

我正在使用WPF

2 个答案:

答案 0 :(得分:1)

您的问题的答案可能会找到here

P.S。如果您正在使用XAML开发UI,那么您正在开发WPF Application,而不是Winforms。在Winforms中选择项目类型时,通过选择Windows Forms Application来创建Visual Studio个应用程序。

答案 1 :(得分:0)

XAML:

 <ListView Name="ResultListView">
      <ListView.View>
           <GridView>
              <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding ApplicationName }" Header="File" />
              <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding ClassName }"     Header="Location" />
           </GridView>
      </ListView.View>
 </ListView>

MyObject.cs

class MyObject
{
    public string ApplicationName { get; set; }
    public string ClassName { get; set; }
}

ObservableCollection<MyObject> results = new ObservableCollection<MyObject>();
//Populate some data into results here
ResultListView.ItemsSource =results;