简体   繁体   English

如何在Silverlight中定位标签页的内容?

[英]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. 当我在Silverlight的标签页上放置一个控件时,控件放置约10个像素,右边10个像素。 For example, the following xaml: 例如,以下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: 将产生:

替代文字

How do I position the content at 0,0? 如何将内容定位在0,0?

检查TabItem的控件模板,它可能有一些默认的Margin 10.只是一个猜测

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. 使用blend来修改选项卡控件模板的副本。

You can also add a negative margin to the content. 您还可以为内容添加负边距。 I found the value to be 9 pixels... 我发现这个值是9像素......

<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. 当前版本的VS不允许更改TabControl的模板,但可以使用Blend完成,并且模板上有一个边距。 The main drawback of doing this is that the XAML file will no longer be previewable from Visual Studio. 这样做的主要缺点是XAML文件将不再可从Visual Studio中预览。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM