Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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>

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top