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

RadTabItem HeaderTemplate not responding to binding to UserControl object properties

7 Answers 241 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 13 Jul 2011, 05:32 PM
I am using the RadTabControl to host UserControls within its tabs.  Its ItemsSource property is set to an ObservableCollection<UserControl>.  So, to properly name these tabs I had planned to create a HeaderTemplate and simply bind to the Name property of my UserControl, converting it to a user friendly string of course.  To do this I used the following:

TabControl declaration:
<telerik:RadTabControl x:Name="radtabVariableControlsContainer" Margin="0" d:LayoutOverrides="GridBox" Grid.Column="1" BorderBrush="{x:Null}" ItemsSource="{Binding MainContentControls}" SelectedItemRemoveBehaviour="SelectPrevious" ItemContainerStyle="{StaticResource MainContentItemContainerStyle}"/>

ItemCotainerStyle:
<Style x:Key="MainContentItemContainerStyle" TargetType="{x:Type telerik:RadTabItem}">
            <Setter Property="HeaderTemplate" Value="{StaticResource ContentAreaTabHeaderTemplate}"/>
        </Style>

Finally, the HeaderTemplate:
<DataTemplate x:Key="ContentAreaTabHeaderTemplate">
            <TextBlock Text="{Binding Name, Converter={StaticResource TabHeaderTextConverter}}" FontFamily="Arial" FontSize="13.333"/>
        </DataTemplate>

With this setup, nothing shows up for the header text.  The converter is not the issue because removing it does not solve the problem.  It seems to be that the Binding cannot execute at Runtime because when editing the template in Blend, the Binding works and shows the correct value.  Also, putting any clear text in for the textblock's text property works.

7 Answers, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 14 Jul 2011, 06:50 PM
Just gave it another stab because I read the guide to styling the tab headers for Silverlight controls.  I simply applied my DataTemplate above to the ItemTemplate property of the TabControl.  However, I got the same behavior...
0
Adam
Top achievements
Rank 1
answered on 15 Jul 2011, 03:19 PM
BTW I am running Q2 2011.  I really think both of these solutions should work... help?
0
Petar Mladenov
Telerik team
answered on 18 Jul 2011, 03:33 PM
Hi Adam,

I am unable to reproduce such kind of issue in the RadTabControl from Q2 2011. Could you please check out my test project and modify it if needed so that the problem occurs? Thank you in advance for your cooperation.

Kind regards,
Petar Mladenov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Adam
Top achievements
Rank 1
answered on 18 Jul 2011, 03:55 PM
The key here seems to be in using UserControl objects.  In your MainWindow.xaml.cs change your ItemsSource declaration to the following:

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

I have verified through MSDN that System.Windows.Controls.UserControl.Name is a bindable dependency property:

http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.name.aspx (do a quick Ctrl+f and search for bind to find the paragraph).
0
Petar Mladenov
Telerik team
answered on 21 Jul 2011, 03:45 PM
Hello Adam,

 As could be seen in the mentioned msdn article , binding the Name of the FrameworkEleement is an extremely uncommon scenario. You can test your project with the System.Windows.Controls.TabControl and examine the same result. 

Regards,
Petar Mladenov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Adam
Top achievements
Rank 1
answered on 21 Jul 2011, 03:54 PM
The article does mention this, however they are referencing not having a name for the UserControl object and instead deriving that name at run time from a bound property.  Additionally, they say that this is "uncommon", they do not say it is not possible.  Anyway, I simply want to use the Name property to reflect the RadTabControl's Header text, why is this not possible?  I will test it with the standard WPF TabControl and present the issue on MSDN's forum.
0
Adam
Top achievements
Rank 1
answered on 21 Jul 2011, 07:52 PM
This is all it took...

<TextBlock Text="{Binding DataContext.Name, Converter={StaticResource TabHeaderTextConverter}, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=telerik:RadTabItem}}" FontFamily="Arial" FontSize="13.333" />

Adding the DataContext."PropertyName" as the path and applying the RelativeSource clause.  This issue was not caused by telerik's controls but by my own inexperience.  Thank you for your time.
Tags
TabControl
Asked by
Adam
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or