DaveK
DaveK

Reputation: 4607

How do I position the content of a tabpage in Silverlight?

When I place a control on a tabpage in Silverlight the control is placed ~10 pixels down and ~10 pixels right. For example, the following xaml:

<System_Windows_Controls:TabControl x:Name=TabControlMain Canvas.Left="0" Canvas.Top="75" Width="800" Height="525" Background="Red" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" Padding="0" Margin="0">
        <System_Windows_Controls:TabItem Header="Test" VerticalContentAlignment="Top" BorderThickness="0" Margin="0" Padding="0" HorizontalContentAlignment="Left">
            <ContentControl>
                <Grid Width="400" Height="200" Background="White"/>
                </ContentControl>
        </System_Windows_Controls:TabItem>    
</System_Windows_Controls:TabControl>

will produce:

alt text

How do I position the content at 0,0?

Upvotes: 1

Views: 756

Answers (4)

Jim
Jim

Reputation:

You can also add a negative margin to the content. I found the value to be 9 pixels...

<System_Windows_Controls:TabControl x:Name=TabControlMain Canvas.Left="0" Canvas.Top="75" Width="800" Height="525" Background="Red" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" Padding="0" Margin="0">
        <System_Windows_Controls:TabItem Header="Test" VerticalContentAlignment="Top" BorderThickness="0" Margin="0" Padding="0" HorizontalContentAlignment="Left">
            <ContentControl>
                <Grid Width="400" Height="200" Margin="-9,-9,-9,-9" Background="White"/>
                </ContentControl>
        </System_Windows_Controls:TabItem>    
</System_Windows_Controls:TabControl>

Upvotes: 1

Stefan Rusek
Stefan Rusek

Reputation: 4767

After spending a couple hours fooling around with this problem. Brian is totally right. The current version of VS does not allow changing the TabControl's template, but it can be done using Blend, and there is a margin on the template. The main drawback of doing this is that the XAML file will no longer be previewable from Visual Studio.

Upvotes: 0

Brian Leahy
Brian Leahy

Reputation: 35527

Look at the control template, it has a margin of that size. Use blend to modify the a copy of the tab control's template.

Upvotes: 1

Jobi Joy
Jobi Joy

Reputation: 50038

Check the control template of your TabItem , it might have some default Margin of 10. Just a guess

Upvotes: 2

Related Questions