I set the control's IsEnabled property based on whether SelectedIndex> = 0 is selected in the ListBox. I can do this in the code behind, but I wanted to create a value converter for this behavior, as I often do it.
I created this value converter to handle the task and bound it to the IsEnabled property:
[ValueConversion(typeof(Selector), typeof(bool))]
public class SelectorItemSelectedToBooleanConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value == null || !(value is Selector))
return null;
var control = value as Selector;
return control.SelectedIndex >= 0;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
The converter is called only once when the application loads. It does not work when the SelectedIndex changes.
So my question is what causes Value Converter? I assume that when the data is bound, is there a way to make the converter work under different circumstances? Am I even asking the right question?