<ListView Name="BscAndMscListView" MaxHeight="200" MaxWidth="250" VerticalAlignment="Top" Opacity="0.8" ItemsSource="{Binding}">
<ListView.View>
<GridView AllowsColumnReorder="true" >
</GridView>
</ListView.View>
</ListView>
后台代码:
GridView tempGridView = (GridView)this.BscAndMscListView.View;
foreach (DataColumn col in resultTable.Columns)
{
GridViewColumn gvc = new GridViewColumn();
gvc.Header = col.ColumnName;
Binding binding = new Binding();
binding.Path = new PropertyPath(col.ColumnName);
gvc.DisplayMemberBinding = binding;
tempGridView.Columns.Add(gvc);
}
this.BscAndMscListView.DataContext = resultTable;
这样可以实现在WPF中动态改变列