gpt4 book ai didi

wpf - 选择组合框项目时启用文本框

转载 作者:行者123 更新时间:2023-12-04 17:25:41 27 4
gpt4 key购买 nike

我想在选择 comboboxitem 时启用文本框。请注意,组合框项目未定义,而是我使用组合框中的项目源来获取组合框项目列表。我想在选择组合框项目时更改文本框的属性。

(粘贴到原始问题的评论)

<DataTrigger Binding="{Binding ElementName=cmbInstrumentType,
Path=SelectedIndex}"
Value="1" >
<Setter Property="IsEnabled" Value="true" />
<Setter Property="Background" Value="White" />
</DataTrigger>

我只希望它在 XAML 中而不是在后面的代码中。我不想对每个索引值都重复这一点——

最佳答案

尽管更好的方法是使用 MVVM 模式并绑定(bind)到 ViewModel 中的属性(如 Dabblenl 建议的那样),但我认为您可以像这样实现您想要的:

    <StackPanel>
<ComboBox ItemsSource="{Binding Items}" Name="cmbInstrumentType"/>
<TextBox>
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=cmbInstrumentType, Path=SelectedItem}" Value="{x:Null}">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</StackPanel>

如果在组合框中未选择任何项目,这将禁用文本框。

编辑:扩展代码段

关于wpf - 选择组合框项目时启用文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10514375/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com