WPF - 使用 IsInitialized 作为属性触发器失败
该对象是一个 ListBoxItem,尽管我也尝试过使用面板。
我收到此错误消息:InvalidOperationException 内的 Property can not be null on Trigger.
。
这是触发器:
<Trigger Property="IsInitialized" Value="true">
<Setter TargetName="MyPanel" Property="Background" Value="AliceBlue">
</Setter>
</Trigger>
注意:我不能使用Loaded
,因为我不希望它在呈现控件时触发。就在初始化时。
这个属性存在...为什么不起作用?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
IsInitialized
属性不是依赖属性< /a>.触发器只能与依赖属性一起使用。但问题是为什么需要这样的触发器?因为直接在
MyPanel
上指定Background
属性或者以`ListBoxItem'的样式来实现同样的效果。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 onMyPanel
or in the style of `ListBoxItem'.