I have a List of objects and a ListView where I display this list. Such an object has some properties, they are bound to the columns of the ListView.
<ListView x:Name="_fileNameList" FontSize="12" SourceUpdated="_fileNameList_SourceUpdated" TargetUpdated="_fileNameList_TargetUpdated">
<ListView.View>
<GridView x:Name="FileNameAttributes" >
<GridViewColumn Header="File Name" Width="200" DisplayMemberBinding="{Binding fileName}"/>
<GridViewColumn Header="Size" Width="80" DisplayMemberBinding="{Binding size}"/>
<GridViewColumn Header="Date" Width="80" DisplayMemberBinding="{Binding date}"/>
<GridViewColumn Header="Time" Width="80" DisplayMemberBinding="{Binding time}"/>
<GridViewColumn Header="New Name" Width="300" DisplayMemberBinding="{Binding newFileName}"/>
</GridView>
</ListView.View>
</ListView>
This part is working fine.
Now I want to change the Foreground color of the newFileName column in a single row, but only if it is equal to the ‘fileName’ in the same row.
Can I do this in XAML or do I have to go to the code behind file?
I would like it best if I could handle it in XAML, because I think its a pure design issue, but I have no idea, where to start or where to put this, (can I do String comparisons in XAML?)
So I tried to handle this in the code behind file. I thought there must be an event that is raised when the ListView has changed, I tried the SourceUpdated event, but it is not entered when I change the content of my list.
The next problem would be, how to access those ListView items …
Can anyone give me an idea how I can solve this?
You can do this using MultiBinding and MultiConverter.
You will need to write a MultiConverter which takes fileName and newFileName and returns true if they are equal
The code for EqualityConverter is as below :