gpt4 book ai didi

wpf - 我如何根据 wpf 中的 ListView 项 HarfNotu 值更改 ListView 项背景颜色

转载 作者:行者123 更新时间:2023-12-03 14:26:53 24 4
gpt4 key购买 nike

我的 ListView 看起来像:
http://oi36.tinypic.com/ek5n3o.jpg

我的 ListView xaml:

<ListView  Name="notListView" Width="550" HorizontalAlignment="Left">
<ListView.View>
<GridView AllowsColumnReorder="true">
<GridViewColumn Header="Ders Kodu" Width="100" DisplayMemberBinding="{Binding Path=DersKodu}" />
<GridViewColumn Header="Ders Adı" Width="200" DisplayMemberBinding="{Binding Path=DersAdi}" />
<GridViewColumn Header="Vize" Width="50" DisplayMemberBinding="{Binding Path=Vize}" />
<GridViewColumn Header="Final" Width="50" DisplayMemberBinding="{Binding Path=Final}" />
<GridViewColumn Header="Ortalama" Width="60" DisplayMemberBinding="{Binding Path=Ortalama}" />
<GridViewColumn Header="Harf Notu" Width="60" DisplayMemberBinding="{Binding Path=Harf}" />
</GridView>
</ListView.View>
</ListView>

我的 .cs 代码:
notListView.ItemsSource = notGoruntule(1, 1); // notGoruntule() function returns an Arraylist, which contains my "Notlar" objects.

我试过这个:
ListViewItem lvitem = (ListViewItem)notListView.Items[0];
lvitem.Background = Brushes.Red;

但第一行抛出:
Unable to cast object of type 'OBS_Interface_5.Classes.Notlar' to type 'System.Windows.Controls.ListViewItem'.

我如何解决这个问题?

最佳答案

您可以 Style ListViewItem直接在xaml中,

例子:

假设您的“Harf”变量是一个字符串,您可以尝试

<ListView Name="notListView"
Width="550"
HorizontalAlignment="Left">
<ListView.Resources>
<Style TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding Harf}"
Value="1">
<Setter Property="Background"
Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.Resources>
...

现在任何 ListView “Harf”值为 1 的行将具有“红色” Background

关于wpf - 我如何根据 wpf 中的 ListView 项 HarfNotu 值更改 ListView 项背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16126393/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com