One way is to bind IsEnabled on the control(s) to the ComboBox SelectedIndex or SelectedItem property using a value converter[^] on the binding to convert the Selectedxxx value to a bool.
\[System.Windows.Data.ValueConversion(typeof(int), typeof(bool))\]
public class SelectedIndexToIsEnabledConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((int)value >= 0) ? true : false;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new System.NotImplementedException();
}
}
<UserControl.Resources >
<local:SelectedIndexToIsEnabledConverter x:Key="SelectedIndexToIsEnabledConverter" />
</UserControl.Resources>
...
Example binding:
IsEnabled="{Binding Path=SelectedIndex,ElementName=comboBox1,Converter={StaticResource SelectedIndexToIsEnabledConverter},Mode=OneWay}"
Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Friday, July 15, 2011 12:33 PM