RadComboBox Binding Issues

2 posts, 0 answers
  1. Matthew Calhoun
    Matthew Calhoun avatar
    6 posts
    Member since:
    Nov 2009

    Posted 05 May 2010 Link to this post

    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?


  2. Konstantina
    Konstantina avatar
    2332 posts

    Posted 12 May 2010 Link to this post

    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,
    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.
Back to Top