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

ItemDropDownContentTemplate does not find display items name

1 Answer 119 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Yann
Top achievements
Rank 1
Yann asked on 08 Dec 2011, 05:29 PM
Hello,

I try to display a list of UserControls in a RadTabControl and to use a UserControl property (name) to display tab header and dropdown items.

According to this post (http://www.telerik.com/community/forums/wpf/tabcontrol/radtabitem-headertemplate-not-responding-to-binding-to-usercontrol-object-properties.aspx), I succeded in displaying Tab Header with UserControl "Name" property.
To do this, I use a RelativeSource :

Text

 

 

="{Binding DataContext.Name, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=telerik:RadTabItem}}"

 


I have used your TabControl-Q1.zip sample project (from post above) where I have modified MainWindow.xaml.cs file to create a list of UserControls :

this

 

 

.radtabVariableControlsContainer.ItemsSource =

 

 

 

Enumerable.Range(0, 10).Select(x => new UserControl() { Name = "name" + x });

 


My RadTabControl and related template definition is this one :
<Grid>
  
        <Grid.Resources>
  
            <DataTemplate x:Key="ContentAreaTabHeaderTemplate">
                <TextBlock Text="{Binding DataContext.Name, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=telerik:RadTabItem}}" FontFamily="Arial" FontSize="13.333" />
            </DataTemplate>
  
        </Grid.Resources>
  
        <telerik:RadTabControl x:Name="radtabVariableControlsContainer"                               
                               BorderBrush="{x:Null}"
                               SelectedItemRemoveBehaviour="SelectPrevious"
                               ItemTemplate="{StaticResource ContentAreaTabHeaderTemplate}"
                               DropDownDisplayMode="Visible"
                               ItemDropDownContentTemplate="{StaticResource ContentAreaTabHeaderTemplate}"/>
  
    </Grid>

It so work find for ItemTemplate to display Tabs Header, but I don't succeed in displaying UserControls names in DropDown.
The "name" property never appear in dropdown...

Many thanks for your help !

Yann

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 13 Dec 2011, 01:26 PM
Hi Yann,

 The behavior you have come up is expected. Binding to RelativeSource traverses the Visual Tree to find the right datacontext. But this cannot be applied to elements in the DropDownContent of a DropDownButton because this DropDownContent is actually a Popup and it is located on other VisualTree, different from the TabControl's one. So I highly suggest you to use ViewModels that are not UserControls or other Visual Elements and you won't need to use "FindAncestor" type of binding.

Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TabControl
Asked by
Yann
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or