嗨,我有listview
两列,“文件夹”和“状态”。如果“状态”成员的数据为“已锁定”,如何将“状态”成员的前景更改为绿色,如果其数据为“未锁定”,如何将其更改为红色。
例子
Folder | Status
----------+--------------------------------------------
xxxx | Locked <--To be appeared as green
yyyyy | Unlocked <-- To be appeared as red
对不起,我的英语不好。
编辑: - - - - - - - - - - - - - - - - -
嘿,我尝试了你的解决方案,但我仍然无法让它工作。
看看我做错了什么。
<ListView x:Name="FoldersListView" Margin="11,202,8,98" Foreground="Black" Background="#FFFFCFCF" BorderBrush="Transparent" FontWeight="Bold">
<ListView.View>
<GridView>
<GridViewColumn Header="Folder" Width="300" DisplayMemberBinding="{Binding Path = FolderPath}"/>
<GridViewColumn Header="Status" Width="100" DisplayMemberBinding="{Binding Path = FolderStatus}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Locked}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="Red"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Locked}" Value="True">
<Setter Property="Foreground" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Locked}" Value="False">
<Setter Property="Foreground" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>