Binding IsSelected

6 posts, 0 answers
  1. Jarred Froman
    Jarred Froman avatar
    57 posts
    Member since:
    Aug 2008

    Posted 06 Aug 2008 Link to this post

    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

  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 07 Aug 2008 Link to this post

    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.
  3. Andrew
    Andrew avatar
    6 posts
    Member since:
    Aug 2008

    Posted 26 Aug 2008 Link to this post

    Valeri,

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

    Thanks,
    Andrew
  4. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 01 Sep 2008 Link to this post

    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.
  5. Richardsonke
    Richardsonke avatar
    93 posts
    Member since:
    Jul 2007

    Posted 12 Jan 2010 Link to this post

    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
  6. Richardsonke
    Richardsonke avatar
    93 posts
    Member since:
    Jul 2007

    Posted 12 Jan 2010 Link to this post

    Sorry, it seems to be working.  I accidentally put the wrong property name in the binding.

    -Keith
Back to Top