Skip to content

ConditionBehavior

Brian Lagunas edited this page Apr 10, 2023 · 4 revisions

ConditionBehavior attaches to a trigger and controls the conditions on which to fire the actions.

This behavior blocks an action from occurring if the specified Condition returns false.

SampleCode

XAML

<Button x:Name="Button">
    <Behaviors:Interaction.Triggers>
        <Behaviors:EventTrigger EventName="Click" SourceObject="{Binding ElementName=Button}">
            <Behaviors:Interaction.Behaviors>
                <Behaviors:ConditionBehavior>
                    <Behaviors:ConditionalExpression>
                        <Behaviors:ComparisonCondition LeftOperand="{Binding Path=Items.Count, ElementName=TabControl}" RightOperand="0" />
                    </Behaviors:ConditionalExpression>
                </Behaviors:ConditionBehavior>
            </Behaviors:Interaction.Behaviors>
            <Behaviors:ChangePropertyAction TargetObject="{Binding ElementName=DataTriggerRectangle}" PropertyName="Fill" Value="LightYellow"/>
        </Behaviors:EventTrigger>
    </Behaviors:Interaction.Triggers>
</Button>