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