XAML Binding RadComboBox SelectedValuePath to an attached property of a RadComboBoxItem

2 posts, 0 answers
  1. gk
    gk avatar
    24 posts
    Member since:
    Jul 2010

    Posted 09 Mar 2012 Link to this post

    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

  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 14 Mar 2012 Link to this post

    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 >>
  3. DevCraft banner
Back to Top