使用 Powershell 在 WPF 中禁用组合框
Disable Combobox in WPF using Powershell
一旦我 select 任何其他项目(如单选按钮项目),我就试图 disable/Gray 出组合框。我使用 Visual Studio 创建了 WPF 表单,并在 PowerShell 中使用了相同的 xaml 表单。因此,在后端是基于 selection 执行的 PowerShell 函数。一个这样的要求是当我 select 一个针对组合框的单选按钮时获取数据。组合框中的项目 selected 应与其他组合框项目匹配,否则我的功能将无法工作。我面临的问题是我无法 Disable/Gray 解决它,即使我尝试在 PowerShell 中设置项目 isenable=$false。如果我在 XAML 中设置相同,它可以工作,但它不满足要求,否则我根本无法 select 这些项目。这是代码
<RadioButton Name="Radio_VM" Content="ASR Status" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="30,382,0,0" RenderTransformOrigin="0.133,0.393"/>
<ComboBox Name="Client" HorizontalAlignment="Left" Margin="15,230,0,0" VerticalAlignment="Top" Width="120" IsDropDownOpen="False" SelectedIndex="2" >
<ComboBoxItem Content="ABC"/>
<ComboBoxItem Content="DEF"/>
</ComboBox>
一旦我 select 单选按钮,它应该使组合框变灰。
您可以将 Style
与绑定到 RadioButton
的 IsChecked
属性 的 DataTrigger
结合使用:
<ComboBox Name="Client" HorizontalAlignment="Left" Margin="15,230,0,0" VerticalAlignment="Top" Width="120" IsDropDownOpen="False" SelectedIndex="2">
<ComboBox.Style>
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=Radio_VM}" Value="True">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<ComboBoxItem Content="ABC"/>
<ComboBoxItem Content="DEF"/>
</ComboBox>
一旦我 select 任何其他项目(如单选按钮项目),我就试图 disable/Gray 出组合框。我使用 Visual Studio 创建了 WPF 表单,并在 PowerShell 中使用了相同的 xaml 表单。因此,在后端是基于 selection 执行的 PowerShell 函数。一个这样的要求是当我 select 一个针对组合框的单选按钮时获取数据。组合框中的项目 selected 应与其他组合框项目匹配,否则我的功能将无法工作。我面临的问题是我无法 Disable/Gray 解决它,即使我尝试在 PowerShell 中设置项目 isenable=$false。如果我在 XAML 中设置相同,它可以工作,但它不满足要求,否则我根本无法 select 这些项目。这是代码
<RadioButton Name="Radio_VM" Content="ASR Status" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="30,382,0,0" RenderTransformOrigin="0.133,0.393"/>
<ComboBox Name="Client" HorizontalAlignment="Left" Margin="15,230,0,0" VerticalAlignment="Top" Width="120" IsDropDownOpen="False" SelectedIndex="2" >
<ComboBoxItem Content="ABC"/>
<ComboBoxItem Content="DEF"/>
</ComboBox>
一旦我 select 单选按钮,它应该使组合框变灰。
您可以将 Style
与绑定到 RadioButton
的 IsChecked
属性 的 DataTrigger
结合使用:
<ComboBox Name="Client" HorizontalAlignment="Left" Margin="15,230,0,0" VerticalAlignment="Top" Width="120" IsDropDownOpen="False" SelectedIndex="2">
<ComboBox.Style>
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=Radio_VM}" Value="True">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
<ComboBoxItem Content="ABC"/>
<ComboBoxItem Content="DEF"/>
</ComboBox>