Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何基于选中单选按钮控制组合框的可见性_C#_Wpf_Xaml - Fatal编程技术网

C# 如何基于选中单选按钮控制组合框的可见性

C# 如何基于选中单选按钮控制组合框的可见性,c#,wpf,xaml,C#,Wpf,Xaml,我有一个快速的WPF问题,关于我的组合框的可见性,关于是否选中按钮。目标是,当用户选中单选按钮“btnCurrent”时,组合框:cboHistorySequence将被隐藏,当选中按钮“btnHistory”时,它将出现 查看:这里有单选按钮“btnCurrent”和“btnHistory”,以及组合框cboHistorySequence。 <RadioButton x:Name="btnCurrent" IsChecked="{Binding IsCurrentSelected, U

我有一个快速的WPF问题,关于我的
组合框的可见性,关于是否选中按钮。目标是,当用户选中单选按钮“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>