Margin 属性的一些边界情况说明 --转http://blog.csdn.net/ghj1976/article/details/4987686
Margin 属性的一些边界情况说明
我们来看例子,下面的椭圆显示的将不是完整的一个椭圆。
Xaml 文件:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="MySilverlight3StudyApplication.MainPage" Width="640" Height="480" mc:Ignorable="d"> <Ellipse Stroke="Black" StrokeThickness="10" Height="64" Margin="313,256,200,30" VerticalAlignment="Top" HorizontalAlignment="Left" Width="197"/> UserControl>
执行效果如下图:
出现椭圆被劫了一部分的原因是 Margin="313,256,200,30" 在作怪。
Margin:获取或设置元素的外边距。上面的313,256,200,30 依次是 left,top,right,bottom
上面的右边距X坐标是通过下面算出来的 640(父控件宽度)-200(right Margin) = 440。 而正常椭圆的最右边点的X坐标为 313(left Margin)+10(left StrokeThickness)+197(Ellipse Width)+10(right StrokeThickness)= 530。
由于椭圆的最右边已经在 计算出来的右边距之外了,在之外的部分就没有显示,所以就会有上面的情况发生。