0

I want to grey out some text when some piece of data is "Ignored", but I don't want the grey out to happen when the item is selected. (Specifically, in high contrast mode, setting the color to the grey value causes the text to be unreadable)

This was my first attempt to do that.

<Style> <!-- .... --> <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextColor}}" /> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <!-- Set gray text when not selected, and ignored. --> <Condition Property="ListBoxItem.IsSelected" Value="false" /> <Condition Binding="{Binding Ignored}" Value="true" /> </MultiDataTrigger.Conditions> <Setter Property="Control.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextColor}}" /> </MultiDataTrigger> </Style.Triggers> </Style> 

This fails at runtime because MultiDataTrigger needs Binding to be set on its conditions. (At least, I think that's why it is failing.)

How can I work around this problem?

2 Answers 2

3

Depending on where exactly you are using the Style, you can convert the first Condition to bind to the ListBoxItem.IsSelected property by using a RelativeSource binding.

Sign up to request clarification or add additional context in comments.

3 Comments

This is being applied to <ListBox.ItemContainerStyle>.
try this inside your first Condition: Binding = {Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}
Also - you should capitalize 'True' and 'False' inside your conditions - it's standard in XAML, even though it's not standard for xml. There are cases where it makes a difference.
2

Upvoted Andrew's answer, I think you want to be binding to the IsSelected property of the ListBoxItem, using RelativeSource, although I'd try it this way:

<Condition Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=Self}}" Value="false" /> 

That worked for me, using a Style in a ResourceDictionary, and using it in a ListBox by setting the ItemContainerStyle property.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.