enisn/UraniumUI

Allow binding to HeaderTemplate and ContentTemplate of material:TabItem

StepKie opened this issue · 2 comments

In our code, we wanted to reuse a named DataTemplate that was defined in our Styles.xaml:

<DataTemplate x:Key="TabHeaderTemplate" x:DataType="material:TabItem">
        <Label
            Padding="0,0,0,5"
            HorizontalOptions="Center"
            VerticalOptions="Center"
            LineBreakMode="MiddleTruncation"
            Text="{Binding Title}">
            <Label.Triggers>
                <DataTrigger Binding="{Binding IsSelected}" TargetType="Label" Value="True">
                    <Setter Property="TextColor" Value="{StaticResource Primary}" />
                    <Setter Property="Scale" Value="1.2" />
                </DataTrigger>
                <DataTrigger Binding="{Binding IsSelected}" TargetType="Label" Value="False">
                    <Setter Property="TextColor" Value="Gray" />
                    <Setter Property="Scale" Value="1" />
                </DataTrigger>
            </Label.Triggers>
        </Label>
    </DataTemplate>

and apply as an implicit style it as a default to all TabItem s like so:

<Style TargetType="material:TabItem">
  <Setter Property="HeaderTemplate" Value="{StaticResource TabHeaderTemplate}" />
</Style>

Currently, this is not possible, since TabItem.cs does not expose its properties DataTemplate and ContentTemplate as BindableProperties.

#662 would enable this possibility.

@enisn Unfortunately, this is not resolved after the merge of #662 for us.

Back when I implemented it, I tested it in the demo/UraniumApp project, and it worked - otherwise I would not have created the PR. Currently, it does not work when I try to use it in my app with UraniumUI 2.9.0.

i.e., the above approach (defining a DataTemplate for TabItem in Styles.xaml, and using it as an implicit style throughout the app) should work when I define a TabItem anywhere in the app, and it should replace the TabView.DefaultHeaderItemTemplate

Currently it still only works when I bind it explicitly with <material:TabItem Title="Test" HeaderTemplate="{StaticResource TabHeaderTemplate}">, otherwise it uses the Default template.

Neither does the approach of defining it as the TabView.TabHeaderItemTemplate instead of the TabItem.HeaderTemplate. In this case, it fails to initialize and throws an Exception in TabView.RenderHeaders()

@enisn Unfortunately, this is not resolved after the merge of #662 for us.

Back when I implemented it, I tested it in the demo/UraniumApp project, and it worked - otherwise I would not have created the PR. Currently, it does not work when I try to use it in my app with UraniumUI 2.9.0.

i.e., the above approach (defining a DataTemplate for TabItem in Styles.xaml, and using it as an implicit style throughout the app) should work when I define a TabItem anywhere in the app, and it should replace the TabView.DefaultHeaderItemTemplate

Currently it still only works when I bind it explicitly with <material:TabItem Title="Test" HeaderTemplate="{StaticResource TabHeaderTemplate}">, otherwise it uses the Default template.

Neither does the approach of defining it as the TabView.TabHeaderItemTemplate instead of the TabItem.HeaderTemplate. In this case, it fails to initialize and throws an Exception in TabView.RenderHeaders()

Thanks for your detailed explanation, I definitely understood the problem. I'll take a look at it about what to do