1

I'm trying to use a special binding for comparisons found here and recommended on another question. NEQ is an added operator that just gives the opposite result of EQ. An InvalidOperationException is thrown every time with the message "Must have non-null value for 'Binding'".

I've tried reducing the statements to just {Binding SourceExpanded} in the condition for testing and even that throws the same exception.

Source, SourceExpanded, and SourceCollapsed are all dependency properties defined in the class this style is associated with.

Is the issue, that you can't bind to a dependency property with a null value? And if so, why is the property value not allowed to be null?

<Style.Triggers>
    <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
            <Condition Property="IsExpanded" Value="True"/>
            <Condition Binding="{local:ComparisonBinding SourceCollapsed, NEQ, {x:Null}}" Value="{x:Null}"/>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="{Binding SourceExpanded}"/>
    </MultiDataTrigger>
    <MultiDataTrigger>
        <MultiDataTrigger.Conditions>
            <Condition Property="IsExpanded" Value="False"/>
            <Condition Binding="{local:ComparisonBinding SourceCollapsed, NEQ, {x:Null}}" Value="{x:Null}"/>
        </MultiDataTrigger.Conditions>
        <Setter Property="Source" Value="{Binding SourceCollapsed}"/>
    </MultiDataTrigger>
</Style.Triggers>
trigger_segfault
  • 554
  • 1
  • 6
  • 23

2 Answers2

4

I know it is kind of late, you must have solved your problem, if not, here is how to solve it.

You need to change <Condition Property="IsExpanded" Value="True"/> to <Condition Binding="{Binding IsExpanded, RelativeSource={RelativeSource Self}}" Value="True" />

Ray Tang
  • 75
  • 1
  • 10
  • I have tried your solution on a simple TextBlock, and it doesn't work, same exception is thrown. – abhinov Nov 08 '19 at 14:48
0

Building upon Ray's and this answer: for the MultiDataTrigger Condition element, use explicit Binding instead of Property, and define a default value if null, using TargetNullValue. Here is the code:

<MultiDataTrigger>
    <MultiDataTrigger.Conditions>
        <Condition Binding="{Binding IsMouseOver, TargetNullValue=''}" Value="True"/>
    </MultiDataTrigger.Conditions>
    <Setter Property="Foreground" Value="Black" />
</MultiDataTrigger>
user2315856
  • 162
  • 2
  • 9