Programatically setting the HeaderTemplate

2 posts, 0 answers
  1. Matthew
    Matthew avatar
    13 posts
    Member since:
    Jan 2009

    Posted 02 Feb 2009 Link to this post

    I have a page that contains a RadTabControl much like this:

    <tn:RadTabControl Background="White"
                                   ItemsSource="{Binding Views, Converter={StaticResource pageListTabConverter}}"
                                   SelectedItem="{Binding SelectedView, Mode=TwoWay, Converter={StaticResource pageTabConverter}}" />

    In my converters I am handling multiple types of views to be displayed to the user.  In these converters I set the tab HeaderText as such:

    tab = new RadTabItem {Content = view, DataContext = view.Model};
    var headerBinding = new Binding("HeaderText") {Source = view.Model};
    tab.SetBinding(HeaderedContentControl.HeaderProperty, headerBinding);

    What I'm interested in doing is being able to set the HeaderTemplate style to contain a button so I can let the user click this button to close the object.  In your examples however this is all setup through the xaml.  Is there a way to do this programmatically?

    <Setter Property="HeaderTemplate">
                                    <Grid Margin="3">
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        <TextBlock Text="{Binding Name}" Grid.Column="1" FontSize="11"
                                            Margin="5 0 5 0" VerticalAlignment="Center" />
                                        <Button Content="x" FontSize="11" VerticalAlignment="Center"
                                            Grid.Column="2" />

    Thanks in advanced.

  2. Hristo
    Hristo avatar
    832 posts

    Posted 05 Feb 2009 Link to this post

    Hello Matthew,

    In Silverlight 2 you cannot create DataTemplate in code. The only way is to define it in XAML as a resource. Then you can get a reference in code and set it to the HeaderTemplate property.

    Let me know if you need more help.

    Sincerely yours,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top