我有三个数据数组,它们将填充ListView
一个DisplayMemberBinding
我可以向绑定项添加逻辑以更改ListView
单元格的前景或背景属性吗?
xml:
<Grid>
<ListView x:Name="carList" VerticalAlignment="Top">
<ListView.View>
<GridView>
<GridViewColumn Header="Car" DisplayMemberBinding="{Binding Name}" Width="Auto"/>
<GridViewColumn DisplayMemberBinding="{Binding Make}" Header="Make" Width="Auto"/>
<GridViewColumn DisplayMemberBinding="{Binding Year}" Header="Year" Width="Auto"/>
</GridView>
</ListView.View>
</ListView>
<Button x:Name="generate" Content="Parse" Click="generate_Click" Margin="0,5,5,5" DockPanel.Dock="Top" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
</Grid>
CS:
public MainWindow()
{
InitializeComponent();
}
public class Car
{
public string Name { get; set; }
public string Make { get; set; }
public string Year { get; set; }
}
private void generate_Click(object sender, RoutedEventArgs e)
{
int i = 0;
string[] name = { "Sentra", "IS", "Camry" };
string[] make = { "Nissan", "Lexus", "Toyota" };
string[] year = { "2003", "2011", "2013" };
foreach (string s in name)
{
Car car = new Car();
car.Name = name[i];
car.Make = make[i];
car.Year = year[i];
if (year[i] == "2013")
{
//Do something here
//Make bold, change color, etc.
}
carList.Items.Add(car);
i++;
}
}