2010-07-19 103 views
2

我有兩個組合框如下WPF組合框觸發

<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> 

我嘗試這種風格

<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> 

我希望第一個是,當「所有」來使用XAML和觸發隱藏第二。

謝謝

回答

7
<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>