Combobox in PanelBarItem with different datacontext

2 posts, 0 answers
  1. emw1909
    emw1909 avatar
    1 posts
    Member since:
    May 2007

    Posted 03 Jun 2009 Link to this post

    Please Help, 

    I have a radpanelbar that has one radpanelbaritem in it with an Itemtemplate.  the itemtemplate has various control in it.  I databind the radpanelbaritem to a list by setting the datacontext to the list.  the binding for the controls in the template works.  However I have a seperate combobox in the itemtemplate that needs to be bound to a seperate list.  When I try binding it, everything goes thru without errors, but no items show in the combobox.

    here is the Xaml:



    telerikNavigation:RadPanelBar x:Name="MLSListing" ExpandMode="Multiple">




    <telerikNavigation:RadPanelBarItem IsExpanded="True" ItemsSource="{Binding}">












    <StackPanel Orientation="Horizontal" Margin="5,2,0,0">




    <Image x:Name="RemMLSBtn" Source="Images/Cancel.png" Margin="0,0,10,0"></Image>




    <TextBlock Text="Agent" Margin="0,3,0,0"></TextBlock>




    <telerikInput:RadComboBox x:Name="cmbAgents" Width="100" Height="20" ItemsSource="{Binding}" DisplayMemberPath="FullName" IsEditable="True" IsReadOnly="True" SelectedIndex="0"></telerikInput:RadComboBox>




    <TextBlock Text="MLS#" Margin="0,3,0,0"></TextBlock>




    <TextBox Text="{Binding MLSNumber, Mode=TwoWay}" Width="70" Margin="5,0,10,0"/>




    <TextBlock Text="Price" Margin="0,3,0,0"></TextBlock>




    <TextBox x:Name="Price" Width="75" Text="{Binding Amount, Mode=TwoWay}"/>




    <TextBlock Text="Date" Margin="0,3,0,0"></TextBlock>




    <telerikInput:RadDatePicker Height="20" x:Name="OrgSaleDate" SelectedDate="{Binding Date, Mode=TwoWay}" Width="100" Margin="5,0,10,0"></telerikInput:RadDatePicker>




    <TextBlock Text="MLS Status" Margin="0,3,0,0"></TextBlock>




    <telerikInput:RadComboBox x:Name="cmbMLSStatus" Width="100" Height="22" IsEditable="True" SelectedIndex="-1" DisplayMemberPath="MLSStatus" ItemsSource="{Binding}" Margin="5,0,10,0"/>




    <CheckBox x:Name="REOSale" Content="REO Sale" DataContext="{Binding REOSale, Mode=TwoWay}" Margin="5,0,0,0"/>




















    <StackPanel Orientation="Horizontal" >




    <Image x:Name="AddMLSBtn" Source="Images/Addnew.png" Width="24" Height="24" />




    <TextBlock Text="MLS Listings" Margin="4,0,0,0" VerticalAlignment="Center" />

















    Here is the codebehind that sets the datacontext of the radpanelbaritem and the combobox within the itemtemplate.


    MLSListing.Items(0).dataContext = FRSingle.Listings


    For i As Integer = 0 To MLSListing.Items.Count - 1



        Dim RPI As RadPanelBarItem = MLSListing.ItemContainerGenerator.ContainerFromIndex(i)



        Dim SP As StackPanel = RPI.ItemTemplate.LoadContent



        Dim ComboList As List(Of RadComboBox) = SP.ChildrenOfType(Of RadComboBox)()



        For isp As Integer = 0 To ComboList.Count - 1



            If ComboList.Item(isp).Name = "cmbAgents" Then





                ComboList.Item(isp).DataContext = Agents


            End If
















    What am I doing wrong??

  2. Valeri Hristov
    Valeri Hristov avatar
    2252 posts

    Posted 03 Jun 2009 Link to this post

    Hello Eric,

    I already answered your support ticket, in case anyone has the same problem I am posting the same text:
    The problem is that when you call the LoadContent() method of the DataTemplate, new instances of the controls in the template are created, that are not the same as the controls, displayed in the panel bar. To avoid the problem I would recommend instead of calling:
    ComboList As List(Of RadComboBox) = SP.ChildrenOfType(Of RadComboBox)()

    To call
    ComboList As List(Of RadComboBox) = RPI.ChildrenOfType(Of RadComboBox)()

    Which will find the real RadComboBox controls in the RadPanelBarItem.

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