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

How to set value of RadComboBoxItem in XAML

1 Answer 741 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 27 Oct 2011, 08:26 PM
I create a datatemplate for a combobox as follows:
<DataTemplate x:Key="AircraftTypeTemplate"> 
    <StackPanel Orientation="Horizontal" Width="340">
        
<telerik:RadComboBox>
            
<telerik:RadComboBoxItem>CJ1</telerik:RadComboBoxItem>
            
<telerik:RadComboBoxItem>CJ3</telerik:RadComboBoxItem>
            
<telerik:RadComboBoxItem>Bravo</telerik:RadComboBoxItem>
            
<telerik:RadComboBoxItem>Excel</telerik:RadComboBoxItem>
            
<telerik:RadComboBoxItem>Sovereign</telerik:RadComboBoxItem>
        
</telerik:RadComboBox>
    
</StackPanel>
</DataTemplate>

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?

Like:

    <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?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 28 Oct 2011, 07:20 AM
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" />
</telerik:RadComboBox>

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):
http://www.telerik.com/help/silverlight/radcombobox-features-selection.html

Kind regards,
Valeri Hristov
the Telerik team

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

Tags
ComboBox
Asked by
Rick
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Share this question
or