创建、填充和设置列表视图的样式。我发现的每个示例都倾向于使用大量XAML标记和最少的C#来切换正在运行的标记位。这对我来说是不可能的,因为在编译时我不知道列的组成,也不知道预期的样式。
我(简化)的是这样的:
string[] columns = new string[] { "Test", "Test2" };
ListView lv = new ListView();
/* Add Columns (works */
GridView viewLayout = new GridView();
foreach (string colName in columns)
{
viewLayout.Columns.Add(new GridViewColumn{ Header = colName });
}
lv.View = viewLayout;
/* Add Items (happy to go the .source path if it's easier) */
foreach (object d in GetData())
{
lv.Items.Add(d);
}
/* Example style, fails */
lv.ItemContainerStyle.Setters.Add(
new Setter(Control.BackgroundProperty, *how do you connect the IValueConverter*)
);