Binding to an element in the RadPane.TitleTemplate

3 posts, 1 answers
  1. Jason
    Jason avatar
    21 posts
    Member since:
    Nov 2010

    Posted 14 Dec 2011 Link to this post

    In my RadPane I have a Listbox that is part of a UserControl in the Content section that I need to bind to a ComboBox in the TitleTemplate section; is this possible? A co-worker suggested searching the visual tree but I'm hoping there's a better way. The code currently falls down on the ItemsSource binding in the UserControl. A XAML solution is preferred but code-behind is fine if that is what is required.

    <DataTemplate x:Key="TitleTemplate">
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="*"/>
        <ContentPresenter Content="{Binding}"/>
        <StackPanel Orientation="Horizontal" Grid.Column="1">
          <ComboBox x:Name="Top" ItemsSource="{Binding Source={x:Static TopLevelElements}}"/>
          <ComboBox x:Name="Middle" ItemsSource="{Binding ElementName=Top, Path=SelectedItem.MiddleLevelElements}"/>

    <!--xmlns declarations in example omitted for brevity-->
    <UserControl x:Class="BottomItemView">
        <ListBox x:Name="Bottom" ItemsSource="{Binding ElementName=Middle, Path=SelectedItem.BottomLevelElements}"/>

    Code for customized RadPane:
    Public Class CustomRadPane
      Inherits RadPane
      Public Sub New(ByVal title As Object)
        Me.Title = title
        Me.TitleTemplate = TryCast(FindResource("TitleTemplate"), DataTemplate)
        Me.Content = System.Activator.CreateInstance(BottomItemView)
      End Sub
    End Class
  2. Answer
    Konstantina avatar
    2332 posts

    Posted 19 Dec 2011 Link to this post

    Hi Jason,

    Could you please elaborate more on what exactly you are trying to achieve - you want the selected item in the ListBox to populate the ComboBox, it this true?
    If so, the ComboBox and the ListBox are in different namescopes, so binding through ElementName won't do the trick. You could create a ViewModel and bind both the ListBox and the ComboBox to it.

    All the best,
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft R3 2016 release webinar banner
  4. Jason
    Jason avatar
    21 posts
    Member since:
    Nov 2010

    Posted 19 Dec 2011 Link to this post

    I'm not a fan of ViewModels, but it gets the job done. My custom RadPane now has an inner ViewModel that both the Title and Content can access. The elements of the TitleTemplate are getting it by setting the Title to my VM and the UserControl I am using in the Content has it's DataContext set to the VM.
Back to Top