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

RadComboBox Binding Issues

1 Answer 200 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Matthew Calhoun
Top achievements
Rank 1
Matthew Calhoun asked on 05 May 2010, 03:46 PM

I am using the RadComboBox for Silverlight and I seem to be missing something...here's what I'm trying to accomplish:

I have a custom type class, a business object class, a view model class and XAML.

I'd like the RadComboBox to display a list of two items (values from the custom type). When I select the item from the dropdown, I'd like the value of a property (IsTypeA) on the business object to be set to the value from the custom type (true/false).

I must be missing something, because I can't get this working. Here's my code:
----------------------------------------------------------------------------------------------------------------------
public class CustomType
{
   public string Name { get; set; }
   public bool Value { get; set; }

   
    public override string ToString()
    {
        return Name;
    }

   public static ObservableCollection<CustomType> GetGetCustomTypes()
   {
      return new ObservableCollection<CustomType>
      {
         new CustomType {Name = ResourceStrings.CustomTypeA, Value = true},
         new CustomType {Name = ResourceStrings.CustomTypeB, Value = false}                       
      };
   }
}
----------------------------------------------------------------------------------------------------------------------
public class MyBusinessObject
{
   public string Name {get; set;}
   public bool IsTypeA {get; set;}
   //Other properties and methods omitted for simplicity
}
----------------------------------------------------------------------------------------------------------------------
I then have a ViewModel class. In that class I have these properties:

private MyBusinessObject _selectedItem;

public MyBusinessObject SelectedItem
{
   get { return _selectedItem; }
   set { _selectedItem = value; this.OnPropertyChanged(p => p.SelectedItem); }
}

private ObservableCollection<CustomType> _customTypes;
public ObservableCollection<CustomType> CustomTypes
{
   get { return _customTypes ?? (_customTypes = CustomType.GetCustomTypes()); }
}
----------------------------------------------------------------------------------------------------------------------
Then in my XAML I have:

<TextBox x:Name="txtName" Text="{Binding SelectedItem.Name, Mode=TwoWay />
<telerikInput:RadComboBox ItemsSource="{Binding CustomTypes}"
     SelectedValue="{Binding SelectedItem.IsTypeA, Mode=TwoWay}"
                          Width="125" />

The dropdown is being displayed properly, but the value of IsTypeA from the business object is not being set when the form is first displayed and isn't being updated based on the selection from the dropdown. I know the business object is working properly as the "txtName" field is working properly (populated on form load, updated when I change the text).

Any ideas?

Thanks,
Matt

1 Answer, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 12 May 2010, 10:01 AM
Hi Matthew Calhoun,

Thank you for contacting us.

I have made a sample project using your code snippets. To make it work you will have to assign a value to the _selectedItem. Please refer to the sample project.

If you have further questions please feel free to contact us again.

All the best,
Konstantina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
ComboBox
Asked by
Matthew Calhoun
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Share this question
or