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

Programatically setting the HeaderTemplate

1 Answer 155 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 2
Matthew asked on 02 Feb 2009, 03:29 PM
I have a page that contains a RadTabControl much like this:

<tn:RadTabControl Background="White"
                               fxui:ContentLayout.ContentName="body"
                               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">
                        <Setter.Value>
                            <DataTemplate>
                                <Grid Margin="3">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <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" />
                                </Grid>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>

Thanks in advanced.



1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 05 Feb 2009, 05:03 PM
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,
Hristo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TabControl
Asked by
Matthew
Top achievements
Rank 2
Answers by
Hristo
Telerik team
Share this question
or