Создание реализации IValueConverter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
namespace XAMLConverter
{
public class ComboBoxConverter : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
if (value.ToString() == "Yes")
return "Cleared";
else if (value.ToString() == "No")
return "Not Cleared";
else
return "";
}
catch
{
return "";
}
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Добавьте свое пространство имен в XAML для:
xmlns:conv="clr-namespace:XAMLConverter"
Добавьте ресурс для конвертера:
<Window.Resources>
<conv:ComboBoxConverter x:Key="ComboBoxConverter" />
</Window.Resources>
Затем добавьте свои элементы управления:
<StackPanel>
<ComboBox Name="SelectControl">
<ComboBoxItem Content="Yes" />
<ComboBoxItem Content="No" />
</ComboBox>
<TextBox Text="{Binding ElementName=SelectControl,
Path=SelectedItem.Content,
Converter={StaticResource ComboBoxConverter}}"
/>
</StackPanel>