当`SelectedIndex`大于0时触发
如何在 ComboBox
上设置触发器,当 SelectedIndex
大于 0(基本上,当选择一个选项时)另一个 ComboBox
得到修改的。我有两个 ComboBox,但用户只能从其中之一进行选择。因此,如果我从 ComboBox
A 中选择第一个选项,则 ComboBox
B 应获得 SelectedIndex
为 0 ,反之亦然。
我尝试过使用以下内容,但不确定如何捕获所需的逻辑。
<ComboBox ItemsSource="{Binding AvailableStatuses}"
SelectedItem="{Binding SelectedStatus}"
Grid.Row="1" Grid.Column="1" DisplayMemberPath="Name"
x:Name="Statuses">
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Decisions}" Value="0">
<Setter Property="SelectedIndex" Value="0" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
我应该关注什么样的触发因素?
How can I set a trigger on a ComboBox
that when the SelectedIndex
is greater than 0 (basically, when an option is selected) another ComboBox
gets modified. What I have are two ComboBox
es but the user can only select from one of them. So if I select the first option from ComboBox
A then ComboBox
B should get a SelectedIndex
of 0 , and vice versa.
I've tried toying with the following but not sure how to capture the logic required.
<ComboBox ItemsSource="{Binding AvailableStatuses}"
SelectedItem="{Binding SelectedStatus}"
Grid.Row="1" Grid.Column="1" DisplayMemberPath="Name"
x:Name="Statuses">
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Decisions}" Value="0">
<Setter Property="SelectedIndex" Value="0" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
What sort of trigger should I be looking at?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为无论“SelectedStatus”属性在哪里,只要在 ViewModel 中包含此逻辑就会简单得多。如果传入的值大于 0,请将另一个属性(“SelectedStatus2”?)设置为 0,反之亦然。
I think it would be much simpler to just have this logic in the ViewModel, wherever your "SelectedStatus" property is. If the value coming in is greater than 0, set the other property ("SelectedStatus2"?) to 0 and vice versa.
为什么不直接将
ComboBox
B 的SelectedIndex
属性绑定到ComboBox
A 的SelectedIndex
属性呢?Why not just bind the
SelectedIndex
property ofComboBox
B to theSelectedIndex
property ofComboBox
A?您可以编写一个转换器,如果 SelectedIndex 大于 0,则返回 True/False
You could write a converter that returns True/False if the SelectedIndex is greater than 0