This is a migrated thread and some comments may be shown as answers.

RadButton.IsEnabled won't bind to RadComboBox.SelectedItem via an IValueConverter

1 Answer 122 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 11 Apr 2012, 03:12 PM
I have two RadButtons, a RadComboBox, and a ListBox on a UserControl. I'm trying to bind the IsEnabled property of the Add button to the SelectedItem property of the combo box using a ValueConverter. My xaml looks like so:

<UserControl.Resources>
    <local:SelectedItemToBoolConverter x:Key="SelectedItemToBool"/>
</UserControl.Resources>
  
<Grid x:Name="LayoutRoot" Background="White">
    <StackPanel>
       <sdk:Label Content="Field Value:"/>
        <Grid Margin="0 0 0 4">
            <telerik:RadComboBox x:Name="fieldComboBox"                                    
                                 DisplayMemberPath="Name"
                                 SelectedValuePath="Name"/>
        </Grid>
        <Grid Margin="0 0 0 4">
        <ListBox x:Name="listBox" Height="150"
                     DisplayMemberPath="Name"
                     />
        </Grid>
        <StackPanel Orientation="Horizontal">
            <telerik:RadButton x:Name="addButton"
                               Height="25"
                               Width="75"
                               Margin="0 0 2 0"
                               Content="Add"
                               IsEnabled="{Binding ElementName=fieldComobBox, Path=SelectedItem, Converter={StaticResource SelectedItemToBool}}"
                               Click="addButton_Click" />
            <telerik:RadButton x:Name="deleteButton"
                               Height="25"
                               Width="75"
                               Margin="0 0 2 0"
                               Content="Delete"
                               IsEnabled="{Binding ElementName=listBox, Path=SelectedItem, Converter={StaticResource SelectedItemToBool}}"
                               Click="deleteButton_Click" />
        </StackPanel>
</Grid>

And my SelectedItemToBoolConverter class looks like this:

public class SelectedItemToBoolConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value != null;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

This works fine when binding the IsEnabled property of the Delete button to the SelectedItem property of the ListBox, but does not execute when binding the IsEnabled property of the Add button to the SelectedItem property of the RadComboBox. 

Is there a reason this functionality does not work between those two controls?

Thanks.

EDIT: This code also works as is if I replace the RadComboBox with a standard silverlight ComboBox.


1 Answer, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 17 Apr 2012, 12:31 PM
Hi Andrew,

It seems that the name of the combobox is wrong in the Binding:

IsEnabled="{Binding ElementName=listBox, Path=SelectedItem, Converter={StaticResource SelectedItemToBool}}"

After fixing this, there is no problem in binding the IsEnabled property of the button. I've attached my test project for a reference.

All the best,
Yana
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
ComboBox
Asked by
Andrew
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or