我做了一个样本,为您了解它。 由于它更多的是基于视图的东西,我建议使用转换器并将代码包含在视图和转换器中。请参阅下面的代码。我测试了它,它在我的最后工作正常。
当您选择B时,文本框处于启用状态,当选择更改为任何其他文本框时,文本框将被禁用。
XAML代码:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:viewModel="clr-namespace:WpfApplication1.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525" >
<Window.Resources>
<viewModel:TestConverter x:Key="TestConverter" />
</Window.Resources>
<Grid Margin="329,0,0,0">
<ComboBox x:Name="cmbDMS" HorizontalAlignment="Left" VerticalAlignment="top" Width="120" >
<ComboBoxItem Content="A"/>
<ComboBoxItem Content="B"/>
<ComboBoxItem Content="C"/>
<ComboBoxItem Content="D"/>
<ComboBoxItem Content="E"/>
</ComboBox>
<TextBox Grid.Row="6" Height="60" Width="250" Margin="0,2" IsEnabled="{Binding ElementName=cmbDMS, Path=Text, Converter={StaticResource TestConverter}}" />
</Grid>
</Window>
TestConverter.cs代码:
using System;
using System.Globalization;
using System.Windows.Data;
namespace WpfApplication1.ViewModel
{
public class TestConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
var si = value.ToString();
if (si.Equals("B"))
return true;
}
return false;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
什么是 “isTypeB”?你有没有误认为[另一个网站](http://www.psychicfriendsnetwork.com)? –