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

TextColor / TabTemplate

3 Answers 230 Views
TabView
This is a migrated thread and some comments may be shown as answers.
Decisive Computing
Top achievements
Rank 2
Decisive Computing asked on 10 May 2017, 11:24 AM

One can easily change the background color of the TabHeader, but there is no easy way to change the Text (Foreground) color. The only do this, that I have seen, is to create (via code), custom tab header content (see bottom).

This actually bring up another issue / question: there does not appear to be a way to declare a tab header template. I would prefer to declare my header template in XAML and have it applied to each tab. Am I missing something?

var tab = new TabViewItem
{
    BindingContext = item.OriginalValue
};
var tabLayout = new StackLayout
{
    Spacing = 0,
    StyleClass = new[] { "SubTab" }
};
tabLayout.Children.Add(new Label()
{
    Text = item.Name,
    StyleClass = new[] { "SubTabItemText" }
});
tab.Header.Content = tabLayout;
Tabs.Items.Add(tab);

 

 

3 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 15 May 2017, 10:21 AM
Hello Brian,

Thank you for providing the code implementation from your side.

You can set the ControlTemplate property of the TabViewHeaderItem and eventually apply a Control Template with a structure of your choice. You can add an element whose TextColor property is set. 

 For example, the control template:
 
<ControlTemplate x:Key="iconControlTemplate">
        <Grid BackgroundColor="Transparent" RowSpacing="0">
            <Label Grid.Row="0"
             Text="{TemplateBinding Text}"
             TextColor="DarkGreen"
             FontSize="10"
             HorizontalTextAlignment="Center"
             Margin="0, 0, 0, 6" />
    </Grid>
  </ControlTemplate>

And eventually, applying it to the TabViewHeaderItem:

<telerikPrimitives:TabViewItem.Header>
    <telerikPrimitives:TabViewHeaderItem Text="{Binding Name}"
                             ControlTemplate="{StaticResource iconControlTemplate}" >
    </telerikPrimitives:TabViewHeaderItem>
</telerikPrimitives:TabViewItem.Header>

I believe this is the behavior you are looking for. Please give it a try and update me whether it will work for you.

Have a great rest of the week.

Regards,
Stefan Nenchev
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pavariss
Top achievements
Rank 1
answered on 12 Mar 2018, 09:29 AM
How can i do like this in c# (code be hide) ?
0
Yana
Telerik team
answered on 14 Mar 2018, 09:07 AM
Hello Pavariss,

You could create a class that represents the ControlTemplate, and the class should derive from the layout  being used for the template.  In the concrete case, you could define the sample template like this:

public class TabHeaderTemplate : Grid
{
    public TabHeaderTemplate()
    {
        var content = new Label();
        content.TextColor = Color.DarkGreen;
        content.FontSize = 10;
        content.HorizontalTextAlignment = TextAlignment.Center;
        content.Margin = new Thickness(0, 0, 0, 6);
        content.SetBinding(Label.TextProperty, new TemplateBinding("Text"));
        Children.Add(content, 0, 0);
    }
}

and then assign it to the TabViewHeaderItem like this:

tabViewItem.Header = new TabViewHeaderItem()
{
    Text = "HeaderText",
    ControlTemplate = new ControlTemplate(typeof(TabHeaderTemplate))
};

Hope this will be helpful.

Regards,
Yana
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TabView
Asked by
Decisive Computing
Top achievements
Rank 2
Answers by
Stefan Nenchev
Telerik team
Pavariss
Top achievements
Rank 1
Yana
Telerik team
Share this question
or