1
I have a ListBox
where the data source is a ObservableCollection<string>
.
I would like the items that start with "ATTENTION" to have the red source.
I could do it using one DataTemplate
, one Converter
and a model to apply in a Label
or TextBlock
.
But since I don’t have DataTemplate
changed the scenario. Could I add the Binding and Convert in a Setter
style?
<ListBox x:Name="lstLog" Height="160" Width="775">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Height" Value="19" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
The convert I know would be something like this:
public class CorLogConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value.ToString().StartsWith("ATENÇÃO"))
return new SolidColorBrush(Colors.Red);
else
return new SolidColorBrush(Colors.Black);
}
}
Post the entire statement of Listbox.
– ramaral
@ramaral I’ve already put the Listbox shampoo. I don’t understand what you mean by "statement" in this context
– user26552
Since I didn’t see any Binding with Observablecollection I thought it was not complete. So you’re doing it in code Behind. Is it possible to put it? Is that having a complete example is easier to work on an answer.
– ramaral