为 StackPanel 定义 DataTrigger
如何为 StackPanel
定义 DataTrigger
?它确实有一个 Trigger 属性,但是在此处定义触发器会在启动应用程序时在初始化时出现以下错误:
对象初始化失败 (ISupportInitialize.EndInit)。触发器集合成员必须是 EventTrigger 类型。 ....
这是由以下简单的 DataTrigger
给出的:
<StackPanel x:Name="PersonPanel" DataContext="{Binding CurrentPerson}">
<TextBlock Text="{Binding Id}" />
<TextBlock Text="{Binding Name}" />
<StackPanel.Triggers>
<DataTrigger Binding="{Binding Id}" Value="1">
<Setter TargetName="PersonPanel" Property="StackPanel.Background" Value="Green" />
</DataTrigger>
</StackPanel.Triggers>
</StackPanel>
这是我的第一个 Trigger
,那么我做错了什么?我应该在其他地方定义触发器
吗?
How do I define a DataTrigger
for a StackPanel
? It does have a Trigger
property, but defining a trigger here gives the following error on Initialize when starting the application:
Failed object initialization (ISupportInitialize.EndInit). Triggers collection members must be of type EventTrigger. ....
This is given from the following simple DataTrigger
:
<StackPanel x:Name="PersonPanel" DataContext="{Binding CurrentPerson}">
<TextBlock Text="{Binding Id}" />
<TextBlock Text="{Binding Name}" />
<StackPanel.Triggers>
<DataTrigger Binding="{Binding Id}" Value="1">
<Setter TargetName="PersonPanel" Property="StackPanel.Background" Value="Green" />
</DataTrigger>
</StackPanel.Triggers>
</StackPanel>
This is my first Trigger
ever, so what do I do wrong? Should I define the Trigger
elsewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的事情
Try something like this
试试这个:
try this: