I have a ComboBox whose xaml is as follows
<ComboBox Name="ComboBoxDiscussionType" IsEnabled="{Binding ElementName=ComboBoxDiscussionType, Path=Items.Count, Converter={StaticResource ComboBoxItemsCountToBoolConverter}}"/>
and the converter takes the Items.Count and checks if its greater than 0 if its greater than 0 then enable it else disable it
The goal is enable the ComboBox if the ComboBox only if it has Items in it else disable it,
( self Binding to its item.count )
the following is my converter,
public class ComboBoxItemsCountToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (int)value > 0;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
how do i achieve it? right now the above Binding gives me an error
For reasons that I don’t understand, on Silverlight the
valueas seen by the converter is of typedoublebut it should beint. In fact it is aninton WPF.But since this is the case, just processing it as a
doublefixed the problem:Strangely enough, a more traditional relative source binding doesn’t work either:
but your original element name binding does:
This seems pretty buggy to me, but Silverlight is a strange beast sometimes.