Databindings Incorrect

5 posts, 1 answers
  1. Darren
    Darren  avatar
    57 posts
    Member since:
    May 2009

    Posted 16 May 2009 Link to this post

    Hi,

    I am dynamically filling a RadComboBox based on input from the keyboard.  My XAML looks like this:

            <telerikInput:RadComboBox x:Name="MedName" GotFocus="MedName_GotFocus" SelectionChanged="MedName_SelectionChanged" ItemsSource="{Binding IdentifierNameType}" Text="{Binding Name, Mode=TwoWay}" Grid.Row="1"  Grid.Column="1" IsTextSearchEnabled="False" IsEditable="True" Height="20" Width="200" HorizontalAlignment="Left"
                <telerikInput:RadComboBox.ItemTemplate> 
                    <DataTemplate> 
                        <StackPanel Orientation="Horizontal"
                            <TextBlock Text="{Binding Name}" /> 
                        </StackPanel> 
                    </DataTemplate> 
                </telerikInput:RadComboBox.ItemTemplate> 
            </telerikInput:RadComboBox> 

    My IdentifierNameType class looks like this:

            public class IdentifierNameType 
            { 
                private int identifier = 0
                private string name = ""
     
                public IdentifierNameType() { } 
     
                public IdentifierNameType(int identifier, string name) 
                { 
                    this.identifier = identifier; 
                    this.name = name; 
                } 
     
                [DataMember(Name = "Identifier")] 
                public int Identifier 
                { 
                    get 
                    { 
                        return this.identifier; 
                    } 
                    set 
                    { 
                        this.identifier = value
                    } 
                } 
     
                [DataMember(Name = "Name")] 
                public string Name 
                { 
                    get 
                    { 
                        return this.name; 
                    } 
                    set 
                    { 
                        this.name = value
                    } 
                } 
            } 
     

    Everything looks good except for when I actually select an item from the dropdown.  It looks like my bindings are wrong.  How do I set it to where the IdentifierNameType.Name is bound correctly?  What I am seeing in the text portion of the RadComboBox is the class name.

    Thanks,
    Darren


  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 18 May 2009 Link to this post

    Hi Darren ,

    Instead of binding the RadComboBox.Text property you need to set the TextSearch.TextPath property:
    <telerikInput:RadComboBox telerik:TextSearch.TextPath="Name" ... />

    Where telerik is:
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"

    I am not sure about the binding on the Text property, but unless you bind it to the data context, you will no longer need it, because it is unrelated to the problem.

    Best wishes,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Darren
    Darren  avatar
    57 posts
    Member since:
    May 2009

    Posted 19 May 2009 Link to this post

    Hi Valeri,

    When I try that I get an error that tells me the attachable property is not found.

    Thanks,
    Darren
  4. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 19 May 2009 Link to this post

    Hello Darren ,

    Did you add the following line:
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"

    in your XAML? The final result should look something like this:
    <UserControl x:Class="SilverlightApplication1.SilverlightControl3"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
      xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input">
     <Grid x:Name="LayoutRoot" Background="White">
      <telerikInput:RadComboBox telerik:TextSearch.TextPath="Name" ... />
     </Grid>
    </UserControl>



    Best wishes,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Darren
    Darren  avatar
    57 posts
    Member since:
    May 2009

    Posted 19 May 2009 Link to this post

    Ah!  That worked!  Thank you very much!
Back to Top