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

XAML Binding RadComboBox SelectedValuePath to an attached property of a RadComboBoxItem

1 Answer 173 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
gk
Top achievements
Rank 1
gk asked on 09 Mar 2012, 05:09 PM
In XAML, can you bindRadComboBox SelectedValuePath to an attached property of a  RadComboBoxItem?
I think this may be a WPF/SL limitation where the binding syntax for attached props "(local:LocalClass.SomeValue)" doesn't work, but I can't seem to find a definitive answer.
Anyone know for sure?
Thanks in advance, GK

1 Answer, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 14 Mar 2012, 01:43 PM
Hi Gabe,

Since I assume you are asking for both - WPF and Silverlight, I will give you the solution for both:
WPF: You can bind the property without any problems, for example:

<telerik:RadComboBox IsEditable="True" SelectedValuePath="(telerik:TextSearch.Text)" >
                        <telerik:RadComboBoxItem Content="bb" telerik:TextSearch.Text="ii" /> 
                        <telerik:RadComboBoxItem Content="item 1" telerik:TextSearch.Text="i2" /> 
                        <telerik:RadComboBoxItem Content="item 2" telerik:TextSearch.Text="i3"/> 
                        <telerik:RadComboBoxItem Content="item 3" telerik:TextSearch.Text="i4"/> 
                </telerik:RadComboBox>

As for Silverlight you will need a work-around to make it work: bind the attached property to the Tag property and then the SelectedValuePath to the Tag, for example:

<telerik:RadComboBox IsEditable="True" VerticalAlignment="Center" SelectedValuePath="Tag"
                    SelectionChanged="RadComboBox_SelectionChanged_1">
  
                <telerik:RadComboBoxItem Content="bb" telerik:TextSearch.Text="ii"
                        Tag="{Binding (telerik:TextSearch.Text), RelativeSource={RelativeSource Self}}" />
  
                <telerik:RadComboBoxItem Content="item 1" telerik:TextSearch.Text="i2"
                        Tag="{Binding (telerik:TextSearch.Text), RelativeSource={RelativeSource Self}}" />
  
                <telerik:RadComboBoxItem Content="item 2" telerik:TextSearch.Text="i3"
                        Tag="{Binding (telerik:TextSearch.Text), RelativeSource={RelativeSource Self}}" />
  
                <telerik:RadComboBoxItem Content="item 3" telerik:TextSearch.Text="i4"
                        Tag="{Binding (telerik:TextSearch.Text), RelativeSource={RelativeSource Self}}" />
  
            </telerik:RadComboBox>

However, this seems like a not very good practise, so I would recommend you to data bind your RadComboBox and avoid binding to the attached property.

Greetings,
Konstantina
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
ComboBox
Asked by
gk
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Share this question
or