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

Binding to an element in the RadPane.TitleTemplate

2 Answers 141 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Jason
Top achievements
Rank 1
Jason asked on 14 Dec 2011, 08:00 PM
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.

TitleTemplate:
<DataTemplate x:Key="TitleTemplate">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto"/>
      <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <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}"/>
    </StackPanel>
  </Grid>
</DataTemplate>

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

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

2 Answers, 1 is accepted

Sort by
0
Accepted
Konstantina
Telerik team
answered on 19 Dec 2011, 03:24 PM
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,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Jason
Top achievements
Rank 1
answered on 19 Dec 2011, 10:32 PM
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.
Tags
Docking
Asked by
Jason
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Jason
Top achievements
Rank 1
Share this question
or