microsoft/XamlBehaviors

DataTriggerBehavior doesn't evaluate initially, instead it will wait until the bound value has changed

decademoon opened this issue · 2 comments

Is this intended behavior?

Consider the following:

<interactivity:Interaction.Behaviors>
    <interactions:DataTriggerBehavior Binding="{x:Bind Vm.IsLiked, Mode=OneWay}" Value="False">
        <interactions:GoToStateAction StateName="NotLiked"/>
    </interactions:DataTriggerBehavior>
    <interactions:DataTriggerBehavior Binding="{x:Bind Vm.IsLiked, Mode=OneWay}" Value="True">
        <interactions:GoToStateAction StateName="Liked"/>
    </interactions:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>

The visual state won't be set correctly until Vm.IsLiked actually changes value.

If this is intended behavior, then what is the best way for me to trigger an evaluation? Should I raise a property changed event for IsLiked in my view model at some point? I can't do it in the VM's constructor because there are no registered listeners yet.

I came across this as well. I would be interested in a "clean" solution too 👍

@MartinZikmund, I was having the same issue. After hours of troubleshooting, it ended up being that the DataTriggerBehavior was not functioning correctly inside a ControlTemplate. I took it out of the 'ControlTemplate' and the initial binding started working.