C# 如何基于选中单选按钮控制组合框的可见性
我有一个快速的WPF问题,关于我的C# 如何基于选中单选按钮控制组合框的可见性,c#,wpf,xaml,C#,Wpf,Xaml,我有一个快速的WPF问题,关于我的组合框的可见性,关于是否选中按钮。目标是,当用户选中单选按钮“btnCurrent”时,组合框:cboHistorySequence将被隐藏,当选中按钮“btnHistory”时,它将出现 查看:这里有单选按钮“btnCurrent”和“btnHistory”,以及组合框cboHistorySequence。 <RadioButton x:Name="btnCurrent" IsChecked="{Binding IsCurrentSelected, U
组合框的可见性,关于是否选中按钮。目标是,当用户选中单选按钮“btnCurrent”时,组合框
:cboHistorySequence
将被隐藏,当选中按钮“btnHistory”时,它将出现
查看:这里有单选按钮“btnCurrent”和“btnHistory”,以及组合框cboHistorySequence。
<RadioButton x:Name="btnCurrent" IsChecked="{Binding IsCurrentSelected, UpdateSourceTrigger=PropertyChanged}" Content="Current" Grid.Column="0" Grid.Row="0"/>
<RadioButton x:Name="btnHistory" IsChecked="{Binding IsHistorySelected, UpdateSourceTrigger=PropertyChanged}" Content="History" Grid.Row="0" Grid.Column="1"/>
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Margin="5,0" IsEnabled="{Binding IsHistorySelected, Converter={StaticResource EnabledConverter} }">
<TextBlock HorizontalAlignment="Left" Width="80">History Seq:</TextBlock>
<ComboBox x:Name="cboHistorySequence" Margin="16,0,0,0" Text="{Binding Path=HistorySequence, UpdateSourceTrigger=PropertyChanged}" Width="80" HorizontalAlignment="Left">
<ComboBoxItem>First</ComboBoxItem>
<ComboBoxItem>Last</ComboBoxItem>
</ComboBox>
</StackPanel>
因为要绑定到应用程序中另一个元素的属性,所以应该使用property和Path
,类似于:
<ComboBoxItem>Last</ComboBoxItem>
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=btnCurrent, Path=IsChecked}" Value="True">
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
Last
在样式中放置一个“默认”setter(
)也很有用,就在
之后和
之前
<ComboBoxItem>Last</ComboBoxItem>
<ComboBox.Style>
<Style TargetType="{x:Type ComboBox}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=btnCurrent, Path=IsChecked}" Value="True">
<Setter Property="Visibility" Value="Hidden" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>