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?
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.
Why not just bind the SelectedIndex
property of ComboBox
B to the SelectedIndex
property of ComboBox
A?
You could write a converter that returns True/False if the SelectedIndex is greater than 0
<DataTrigger Binding="{Binding ElementName=Decisions,
Converter={StaticResource IsValueGreaterThanZeroConverter}}" Value="True">
精彩评论