带有 MultiTriggers 的 SourceName
是否可以使用 MultiTrigger 来评估多个元素的属性? 它不位于模板内,而是位于用户控件/窗口内。
例子:
<CheckBox x:Name="checkBox1" />
<CheckBox x:Name="checkBox2" />
<CustomControl>
<CustomControl.ContentTemplate>
<DataTemplate>
<DataTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition
SourceName="checkBox1"
Property="IsChecked"
Value="False" />
<Condition
SourceName="checkBox2"
Property="IsChecked"
Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter
Property="Visibility"
Value="Collapsed" />
</MultiTrigger.Setters>
</MultiTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</CustomControl.ContentTemplate>
在普通的触发器中,我们可以使用 sourceName 来触发这些复选框控件上的属性,但是使用 MultiTrigger,当它尝试查找这些控件时,我会遇到构建错误。
注意:此处
Is it possible to use a MultiTrigger
to evaluate properties on multiple elements? That don't reside within a template, but are within the Usercontrol/Window.
Example:
<CheckBox x:Name="checkBox1" />
<CheckBox x:Name="checkBox2" />
<CustomControl>
<CustomControl.ContentTemplate>
<DataTemplate>
<DataTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition
SourceName="checkBox1"
Property="IsChecked"
Value="False" />
<Condition
SourceName="checkBox2"
Property="IsChecked"
Value="True" />
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter
Property="Visibility"
Value="Collapsed" />
</MultiTrigger.Setters>
</MultiTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</CustomControl.ContentTemplate>
In a normal Trigger
we can use the sourceName to trigger against properties on either of those checkbox controls, but with a MultiTrigger
I get build errors when it attempts to find those controls.
Note: The reason I'm using a DataTemplate
as opposed to a Style
is mentioned here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实可以使用源名称,但您的 DataTemplate 似乎没有正确定义。 我已经尝试填写您的示例,该示例似乎有效:
问题似乎是您没有在 DataTemplate 中定义复选框,而这正是它们需要的位置。
You can indeed use source name, but your DataTemplate doesn't appear to be defined correctly. I've tried filling out your example which seems to work:
The problem appears to be that you don't define your CheckBoxes inside your DataTemplate, which is where they need to be.