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

Binding IsSelected

5 Answers 258 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jarred Froman
Top achievements
Rank 1
Jarred Froman asked on 06 Aug 2008, 02:36 PM
Binding doesn't appear to be working for the IsSelected property on the RadComboBox.  All sorts of errors seem to occur when this happens.  Has anybody else been experiencing this problem?  Here is the section from the XAML:


<
telerik:RadComboBox x:Name="cmbOwnershipLevel" Grid.Row="4" Grid.Column="1" ItemsSource="{Binding OwnershipLevel, Mode=TwoWay}">
    
<telerik:RadComboBox.ItemTemplate>
        
<DataTemplate>
            <telerik:RadComboBoxItem x:Name="radcbitem" IsSelected="{Binding Selected}" Content="{Binding Name}" />
        </DataTemplate>
    </telerik:RadComboBox.ItemTemplate>
</telerik:RadComboBox>


Thanks,
-Jarred Froman

5 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 07 Aug 2008, 09:44 AM
Hello Jarred,

I am sending the same reply as in the support ticket here in case someone else has the same problem:

This scenario is not supposed to work that way. I will try to explain why:

The value of the ItemTemplateProperty is applied to the ContentTemplate property of the ContentPresenter in each RadComboBoxItem when the item in the ItemsSource is not RadComboBoxItem, e.g. this template is applied only when the combo box is bound to a collection of objects, that are not RadComboBoxItem, e.g. when RadComboBox automatically generates its items. Putting a RadComboBoxItem in the template is not the same as putting a RadComboBoxItem directly in the Items collection, or ItemsSource, because the ContentPresenter does not "know" (or care) what's in its ContentTemplate and cannot "tell" RadComboBox that it should not autogenerate a new item. In WPF this can be done with a Style, data trigger, and many other ways, all of which unfortunately are not available in Silverlight.

The only solution for the problem that cames to my mind is to compute which item in the ItemsSource is selected and provide it as a property of the items source object, which could be bound to the SelectedItem property of RadComboBox. Attached is a Silverlight UserControl, demonstrating how to do it. In this control I am using DisplayMemberPath property bind a single property of the data item to the Content of RadComboBoxItem. If you need complex formatting, or ability to display more than one value, you could use the ItemTemplate property.

Doing exactly same with the SelectedIndex property is not currently working, because of some limitations of the Silverlight Framework (we cannot set default values of dependency properties). In this case, you should set the binding in the code-behind instead of XAML.


I understand that this is a common scenario for most of the developers and I will continue to search for better solution, but at the moment I cannot suggest anything better. I am sorry for the inconvenience.

Kind regards,
Valeri Hristov (Silverlight Team)

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Andrew
Top achievements
Rank 1
answered on 26 Aug 2008, 04:19 PM
Valeri,

Could you please provide us with an example of how to work with TwoWay binding properly.

Thanks,
Andrew
0
Valeri Hristov
Telerik team
answered on 01 Sep 2008, 03:18 PM
Hi Andrew,

Unfortunately, I am not able to provide a good working example for TwoWay binding right now. I recommend checking the general data binding articles on silverlight.net:
http://silverlight.net/learn/tutorials/databinding.aspx

another nice resource, explaining the problems you might encounter using TwoWay binding is:
http://www.alancobb.com/blog/2008/07/17/ChangingSilverlightPropertiesDynamicallyWithABindingrelayObject.aspx

Sincerely yours,
Valeri Hristov (Silverlight Team)
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Richardsonke
Top achievements
Rank 1
answered on 12 Jan 2010, 03:08 PM
Is TwoWay binding still not working for binding the SelectedItem property?  The value of the selected item would be an object of a custom class type.  Thanks.

-Keith
0
Richardsonke
Top achievements
Rank 1
answered on 12 Jan 2010, 03:35 PM
Sorry, it seems to be working.  I accidentally put the wrong property name in the binding.

-Keith
Tags
ComboBox
Asked by
Jarred Froman
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Andrew
Top achievements
Rank 1
Richardsonke
Top achievements
Rank 1
Share this question
or