我想以编程方式填充 WPF 列表视图。我认为我接近答案但尚未解决,我使用一种方法来填充列表视图,列表视图在 XAML 中看起来像这样
<ListView Name="listview" HorizontalAlignment="Left" Height="252" Margin="39,110,0,0" VerticalAlignment="Top" Width="340">
<ListView.View>
<GridView x:Name="gridcontrol">
<GridViewColumn/>
</GridView>
</ListView.View>
</ListView>
到目前为止我所做的是:
private void FillListView( String[] texto ) {
GridViewColumn gvc = new GridViewColumn();
gvc.Header = cmbx2.SelectedItem.ToString();
gridcontrol.Columns.Add(gvc);
foreach (String s in texto) {
ListViewItem item = new ListViewItem();
item.Content = s;
listview.Items.Add(item);
}
listview.View = gridcontrol;
}