我有一个ComboBox和一个TextBox,并且只想在TextBox中选择第一个项目时启用/禁用ComboBox。
此代码有效:(选择第一项时禁用)
<ComboBox SelectedIndex="{Binding Mode}">
<ComboBoxItem>Mode 1</ComboBoxItem>
<ComboBoxItem>Mode 2</ComboBoxItem>
<ComboBoxItem>Mode 3</ComboBoxItem>
</ComboBox>
<TextBox Text="{Binding ValueNotForMode1}">
<TextBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding ="{Binding Mode}" Value="0">
<Setter Property="TextBox.IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>此选项不起作用:(选择第一项时启用)
<ComboBox SelectedIndex="{Binding Mode}">
<ComboBoxItem>Mode 1</ComboBoxItem>
<ComboBoxItem>Mode 2</ComboBoxItem>
<ComboBoxItem>Mode 3</ComboBoxItem>
</ComboBox>
<TextBox IsEnabled="False" Text="{Binding ValueForMode1}">
<TextBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding ="{Binding Mode}" Value="0">
<Setter Property="TextBox.IsEnabled" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>不能通过DataTrigger启用控件吗?
或者,当触发器没有发生时,我如何告诉控件该做什么?
发布于 2012-02-08 20:39:53
将IsEnabled="False"从TextBox移动到TextBox.Style。
<Setter Property="TextBox.IsEnabled" Value="False" />有关更清晰的理解,请参阅Dependency Property Value Precedence。
https://stackoverflow.com/questions/9193192
复制相似问题