Wpf 组合框触发器 [英] Wpf ComboBox Trigger
本文介绍了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 和触发器隐藏第二个.
I want when the first is 'All' to hide the second using Xaml and trigger.
谢谢
推荐答案
<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>
这篇关于Wpf 组合框触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文