[英]How to get checked radio button and how to control only one radio button selected in list view
[英]How to control Visibility of ComboBox based on radio button is checked
我有一个快速的 WPF 问题,关于我的ComboBox
在是否选中按钮方面的可见性。 我们的目标是,当用户选中的单选按钮:“btnCurrent”,该ComboBox
: 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>
我试过的
我最初的想法是使用类似的东西并将其绑定到视图模型,但我没有成功。 yall 有什么建议?
Visibility="{Binding IsShowComboBox, Converter={StaticResource VisibilityConverter}
因为您想绑定到应用程序中另一个元素的属性,您应该使用Binding.ElementName
属性和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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.