How to set value of RadComboBoxItem in XAML

2 posts, 0 answers
  1. Rick
    Rick avatar
    18 posts
    Member since:
    Jul 2004

    Posted 27 Oct 2011 Link to this post

    I create a datatemplate for a combobox as follows:
    <DataTemplate x:Key="AircraftTypeTemplate"> 
        <StackPanel Orientation="Horizontal" Width="340">

    It renders fine, but I would like to be able to associate a value with each of the items without having to bind it to some data context. For example I would like the CJ1 comboboxitem to have a value of 5. How would I set those in XAML?


        <telerik:RadComboBoxItem Value="5">CJ1</telerik:RadComboBoxItem> 

    And then how would I bind the SelectedValue of the combobox to the Tag of the selected item?


  2. Valeri Hristov
    Valeri Hristov avatar
    2252 posts

    Posted 28 Oct 2011 Link to this post

    Hello Rick,

    Here is an alternative to the binding - you could put the data items in XAML:
    public class DataItem
        public int ID { get; set; }
        public int Text { get; set; }

    <telerik:RadComboBox DisplayMemberPath="Text">
        <local:DataItem ID="1" Text="one" />
        <local:DataItem ID="2" Text="two" />
        <local:DataItem ID="3" Text="three" />

    You could take a look at the following article for more information about how to retreive the values of the items (the Using SelectedValue and SelectedValuePath section):

    Kind regards,
    Valeri Hristov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top