The object is an ListBoxItem, although I tried with a Panel as well.
I get this error message: Property can not be null on Trigger., within an InvalidOperationException.
Here’s the trigger:
<Trigger Property="IsInitialized" Value="true">
<Setter TargetName="MyPanel" Property="Background" Value="AliceBlue">
</Setter>
</Trigger>
Note: I can’t use Loaded, because I don’t want it to fire whenever the control is rendered. Just at initializiation.
This property exists… why doesn’t it work?
This is because the
IsInitializedproperty is not a Dependency Property. Triggers can only be used with dependency properties.But the question is why would you need such a trigger? Because the same effect can be achieved just by specifying the
Backgroundproperty directly onMyPanelor in the style of `ListBoxItem’.