Hello,
I'm using a RadComboBox binded to an ObservableCollection of my own ViewModels. On my ViewModels I have an IsSelected property binded to the IsSelected property of the RadComboBoxItems. To achieve this, since you can't set a binding in a setter in Silverlight, I've had to inherit from RadComboBox and add this override:
Everything works well except for one single problem. I need to set one of my objects as selected when first getting the items (which I get after loading the control since I get them from a webservice). Basically, when I receive the data and populate the collection I set the first ViewModel's IsSelected property to true. Well, the combobox doesn't select anything. It doesn't matter whether the combobox is editable, but I need it to be editable if it's important.
Once the user selects an item everything works well.
My guess would be that the control virtualizes the items and it doesn't create them until the user opens it for the first time. I've tried setting VirtualizingStackPanel.IsVirtualizing to false to no avail - in fact, when I do that Silverlight encounters an error and doesn't render my view.
How could I fix this problem? By the way, this combobox is in a template so I don't have code-behind. Besides, I'd prefer not to use code-behind if possible, I prefer using MVVM.
I'm using a RadComboBox binded to an ObservableCollection of my own ViewModels. On my ViewModels I have an IsSelected property binded to the IsSelected property of the RadComboBoxItems. To achieve this, since you can't set a binding in a setter in Silverlight, I've had to inherit from RadComboBox and add this override:
protected
override
DependencyObject GetContainerForItemOverride()
{
RadComboBoxItem container =
new
RadComboBoxItem();
Binding selectedBinding =
new
Binding(
"IsSelected"
);
selectedBinding.Mode = BindingMode.TwoWay;
container.SetBinding(RadComboBoxItem.IsSelectedProperty, selectedBinding);
return
container;
}
Everything works well except for one single problem. I need to set one of my objects as selected when first getting the items (which I get after loading the control since I get them from a webservice). Basically, when I receive the data and populate the collection I set the first ViewModel's IsSelected property to true. Well, the combobox doesn't select anything. It doesn't matter whether the combobox is editable, but I need it to be editable if it's important.
Once the user selects an item everything works well.
My guess would be that the control virtualizes the items and it doesn't create them until the user opens it for the first time. I've tried setting VirtualizingStackPanel.IsVirtualizing to false to no avail - in fact, when I do that Silverlight encounters an error and doesn't render my view.
How could I fix this problem? By the way, this combobox is in a template so I don't have code-behind. Besides, I'd prefer not to use code-behind if possible, I prefer using MVVM.