开发者

WPF - using IsInitialized as Property Trigger fails

开发者 https://www.devze.com 2023-02-14 06:33 出处:网络
The object is an ListBoxItem, although I tried with a Panel as well. I get this error message开发者_StackOverflow中文版: Property can not be null on Trigger., within an InvalidOperationException.

The object is an ListBoxItem, although I tried with a Panel as well.

I get this error message开发者_StackOverflow中文版: 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 IsInitialized property 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 Background property directly on MyPanel or in the style of `ListBoxItem'.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号