Skip to main content

Microsoft Silverlight

Answered Question RC0: TabControl Style with ControlTemplate no longer worksRSS Feed

(0)

paupdb
paupdb

Member

Member

8 points

15 Posts

RC0: TabControl Style with ControlTemplate no longer works

In my application I have a Style that I created to remove the annoying margins that the default TabControl puts on its content panel.
In SL 2 Beta 2, this Style worked perfectly. 
Now in RC0, it doesn't - I don't get any errors, but nothing shows in the TabControl, not even the TabItem tabs.

Interestingly, the Style I have applied to my TabItems to remove margins there works fine still in RC0.

Below is the TabControl Style, its basically the same as the default TabControl style, just with Margin = 0 on the ContentHost:

        <!-- Marginless TabControl and TabItem Style -->
        <Style TargetType="winctrl:TabControl" x:Key="MarginlessTabControlStyle">
            <Setter Property="IsEnabled" Value="False" />
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="Background" Value="White" />
            <Setter Property="Foreground" Value="#FF313131" />
            <Setter Property="FontFamily" Value="Trebuchet MS" />
            <Setter Property="FontSize" Value="11" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="winctrl:TabControl">
                        <Grid x:Name="Root">
                            <Grid.Resources>
                                <!-- Brushes -->
                                <SolidColorBrush x:Key="BorderBrush" Color="#FF000000" />
                                <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF" />
                            </Grid.Resources>
                           
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0" />
                                    </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="Disabled1" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>

                            <primitives:TabPanel x:Name="TabPanel" Canvas.ZIndex="1" Grid.Column="0" Grid.Row="0" />

                            <Border x:Name="ContentBorder" Background="{TemplateBinding Background}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" Grid.Column="0" Grid.Row="1" MinHeight="10" MinWidth="10" CornerRadius="0,0,2,2">
                                <ContentControl x:Name="ContentHost"
                                Foreground="{TemplateBinding Foreground}"
                                FontSize="{TemplateBinding FontSize}"
                                FontFamily="{TemplateBinding FontFamily}"
                                HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalAlignment}"
                                Margin="0" />
                            </Border>

                            <Rectangle x:Name="Disabled1" Canvas.ZIndex="1"
                            Grid.Column="0" Grid.Row="0"
                            Grid.ColumnSpan="2" Grid.RowSpan="2"
                            IsHitTestVisible="False"
                            Fill="{StaticResource DisabledBrush}" Opacity="0" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

 

I suspect the default TabControl ControlTemplate has changed somewhere.

paupdb
paupdb

Member

Member

8 points

15 Posts

Answered Question

Re: RC0: TabControl Style with ControlTemplate no longer works

Update to this - this is no longer a bug for me. 
I found the updated documentation for RC0 (through VS Help) and managed to dig up the new TabControl ControlTemplate (which has changed dramatically from Beta 2).

I then discovered on close inspection of the new TabControl ControlTemplate that one can now set the margins on the ContentControl through the TabControl.Padding property.  Which means I no longer need a custom Style or ControlTemplate anymore :)

 

Timmy G
Timmy G

Member

Member

66 points

52 Posts

Re: RC0: TabControl Style with ControlTemplate no longer works

Can you tell me where I can find the xaml for these controls? I'm trying to use my own control template for the tabcontrol and cannot get it to work in RC0. I grabbed the default style from the SilverlightDefaultStyleBrowser and just tried to use it as is (no changes) and my test app won't run.

Timmy G
Timmy G

Member

Member

66 points

52 Posts

Re: RC0: TabControl Style with ControlTemplate no longer works

Nevermind. I found the problem: that tool (SilverlightDefaultStyleBrowser) was showing me the new RC0 xaml (so I no longer need to find it in the help file). The catch was that I couldn't use that xaml until I moved the primative namespace declaration out of the style and into the root. Then it worked and now I can tweak the tab control's control template.

EricBowman
EricBowman

Member

Member

50 points

31 Posts

Re: Re: RC0: TabControl Style with ControlTemplate no longer works

paupdb,

 Will you please post where you found the documentation, all I can find is the Beta 2 documentation.

 Thank you.

Eric

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities