我必须更改ListBox的ItemTemplate的背景颜色,具体取决于布尔值。 这是我的ListBox:
<ListBox Name="itemListBox"
ScrollViewer.VerticalScrollBarVisibility="Visible"
SelectionChanged="itemListBox_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel Width="200">
<TextBlock FontSize="10"
FontWeight="Bold"
VerticalAlignment="Center"
Text="{Binding Path=Value.DocID}" />
<TextBlock FontSize="10"
VerticalAlignment="Center"
TextWrapping="Wrap"
Text="{Binding Path=Value.Serial}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
如果用户删除了一个项目,我想用灰色的backrgound显示他 精度:ListBox绑定到Dictionnary,其中包含一个布尔值“IsDeleted”。 对不起,英语很差 谢谢
答案 0 :(得分:4)
您可以将import sys
import csv
import time
map_array = []
map_array_1 = []
reader = csv.reader(open('input_file.csv', 'rU'))
for row in reader:
map_array.append(row)
for i in map_array:
for j in i:
hold = j.replace(">",",")
map_array_1.append(hold)
writer = csv.writer(open('output_file.csv','wb'),delimiter=',')
for row in map_array_1:
writer.writerow(row)
与ItemContainerStyle
:
DataTrigger
如果您打算动态设置属性并希望背景相应更新,请确保具有<ListBox Name="itemListBox" ScrollViewer.VerticalScrollBarVisibility="Visible" SelectionChanged="itemListBox_SelectionChanged">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Triggers>
<DataTrigger Binding="{Binding Value.IsDeleted}" Value="True">
<Setter Property="Background" Value="Gray" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel Width="200">
<TextBlock FontSize="10" FontWeight="Bold" VerticalAlignment="Center" Text="{Binding Path=Value.DocID}" />
<TextBlock FontSize="10" VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding Path=Value.Serial}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
属性的类正确实现INotifyPropertyChanged接口。