我有以下类结构 -
public class Details
{
public string Customer { get; set; }
public string Serial { get; set; }
public string Model { get; set; }
}
public class Summary
{
public string Header { get; set; }
public List<Details> Details { get; set; }
}
我正在关注这个链接来构建这个要求。
我的要求就像有一个GridView
动态的列,它将由Summary
类列表映射。现在 Header 将与GridViewColumn
header 映射。到现在为止还好。现在从Details
属性,我想再次创建一个GridView
具有动态编号的孩子。使用类属性Details
中定义的类列表和行映射的列数。Details
谁能告诉我正确的解决方案。
编辑链接已更新
我尝试过的
public class DynamicGridViewConverter: IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var dynamicConfig = value as List<Summary>;
if (dynamicConfig != null)
{
var gridView = new GridView();
foreach (var lineColumn in dynamicConfig)
{
DataTemplate template = new DataTemplate();
FrameworkElementFactory frameworkGrid = new FrameworkElementFactory(typeof(Grid));
FrameworkElementFactory frameworkListView = new FrameworkElementFactory(typeof(ListView));
GridView internalGridView = new GridView();
GridViewColumn col1 = new GridViewColumn();
col1.DisplayMemberBinding = new Binding("Customer");
col1.Header = "Customer Header";
internalGridView.Columns.Add(col1);
GridViewColumn col2 = new GridViewColumn();
col2.DisplayMemberBinding = new Binding("Serial");
col2.Header = "Serial Header";
internalGridView.Columns.Add(col2);
GridViewColumn col3 = new GridViewColumn();
col3.DisplayMemberBinding = new Binding("Model");
col3.Header = "Model Header";
internalGridView.Columns.Add(col3);
frameworkListView.SetValue(ListView.ViewProperty, internalGridView);
var itemSourceBinding = new Binding();
itemSourceBinding.Source = lineColumn.Details;
frameworkListView.SetBinding(ListView.ItemsSourceProperty, itemSourceBinding);
frameworkGrid.AppendChild(frameworkListView);
template.VisualTree = frameworkGrid; gridView.Columns.Add(new GridViewColumn() { Header = lineColumn.Header, CellTemplate = template, Width=200});
}
return gridView;
}
return Binding.DoNothing;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
它正在显示View Can not be shared by more than one ListView
我缺少什么部分?