RadTabItem HeaderTemplate not responding to binding to UserControl object properties

8 posts, 0 answers
  1. Adam
    Adam avatar
    38 posts
    Member since:
    Oct 2010

    Posted 13 Jul 2011 Link to this post

    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.
  2. Adam
    Adam avatar
    38 posts
    Member since:
    Oct 2010

    Posted 14 Jul 2011 Link to this post

    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...
  3. UI for WPF is Visual Studio 2017 Ready
  4. Adam
    Adam avatar
    38 posts
    Member since:
    Oct 2010

    Posted 15 Jul 2011 Link to this post

    BTW I am running Q2 2011.  I really think both of these solutions should work... help?
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 18 Jul 2011 Link to this post

    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!

  6. Adam
    Adam avatar
    38 posts
    Member since:
    Oct 2010

    Posted 18 Jul 2011 Link to this post

    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).
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 21 Jul 2011 Link to this post

    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!

  8. Adam
    Adam avatar
    38 posts
    Member since:
    Oct 2010

    Posted 21 Jul 2011 Link to this post

    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.
  9. Adam
    Adam avatar
    38 posts
    Member since:
    Oct 2010

    Posted 21 Jul 2011 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready