Wpf ComboBox Trigger

I have two ComboBoxes as follows

<StackPanel Orientation="Horizontal" > <ComboBox x:Name="cbxOne" Style="{StaticResource demoStyle}" > <ComboBoxItem >One</ComboBoxItem> <ComboBoxItem >Two</ComboBoxItem> <ComboBoxItem >All</ComboBoxItem> </ComboBox> <ComboBox x:Name="cbxTwo"> <ComboBoxItem >1</ComboBoxItem> <ComboBoxItem >2</ComboBoxItem> </ComboBox> </StackPanel> 

I tried this style

 <Style x:Key="demoStyle" TargetType="{x:Type ComboBox}"> <Style.Triggers> <Trigger Property="SelectedValue" Value="All"> <Setter Property="cbxTwo.Visibility" Value="Collapsed"></Setter> </Trigger> </Style.Triggers> </Style> 

I want the first to be "Everything" to hide the second using Xaml and trigger.

thanks

+2
source share
1 answer
  <StackPanel> <ComboBox Name="cbxOne"> <ComboBoxItem>One</ComboBoxItem> <ComboBoxItem>Two</ComboBoxItem> <ComboBoxItem>All</ComboBoxItem> </ComboBox> <ComboBox> <ComboBoxItem>1</ComboBoxItem> <ComboBoxItem>2</ComboBoxItem> <ComboBox.Style> <Style TargetType="{x:Type ComboBox}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=SelectedItem.Content, ElementName=cbxOne}" Value="All"> <Setter Property="Visibility" Value="Collapsed" /> </DataTrigger> </Style.Triggers> </Style> </ComboBox.Style> </ComboBox> </StackPanel> 
+7
source

Source: https://habr.com/ru/post/944562/


All Articles