我试图在一个空的椭圆内绘制一个填充的椭圆(就像一个单选按钮),整个过程是可伸缩的。
我尝试过这种方式(网格看起来是必要的,如果我使用边框,比例看起来就不一样了)
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition Height="5*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Ellipse Stroke="Black" StrokeThickness="3" Grid.RowSpan="3" Grid.ColumnSpan="3"></Ellipse>
<Ellipse StrokeThickness="0" Fill="Red" Grid.Row="1" Grid.Column="1" />
</Grid>当控件为30x30时,填充的椭圆看起来不居中,有一个小的偏移量(看起来它离右下角更近)。如果我将2-5-2改为1-2-1,它从左上角看起来更近。
你知道它为什么会这样吗?更重要的是,我如何才能让它看起来更对称呢?
提前感谢你的帮助(并为我糟糕的英语道歉)。(顺便说一句,我使用的是.Net FW 4.5)
发布于 2016-02-11 18:04:22
据我所知,这是因为你的测量结果。您已经说过控件应该是30x30,但是您将其拆分成不可能均匀分布的方式: 50%到中间列(15像素),剩下15个像素在其他两列之间均匀分布,这是不能均匀完成的。
我的建议是将度量设置为更友好的值,例如32x32 (当我尝试时,这似乎可以很好地工作,这是典型的方法)-但如果您需要它真正可扩展到任何大小,也许可以设置一些属性,让您的对象忽略WPF在元素之间的像素之间进行的“舍入”,以下是我的建议:
MSDN UseLayoutRounding
尝试在网格和椭圆上设置这些。
发布于 2016-02-11 18:35:54
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="3*" />
<RowDefinition Height="5*" />
<RowDefinition Height="3*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Ellipse Stroke="Black" StrokeThickness="3" Grid.RowSpan="3" Grid.ColumnSpan="3"></Ellipse>
<Ellipse StrokeThickness="0" Fill="Red" Grid.Row="1" Grid.Column="1" />
</Grid>https://stackoverflow.com/questions/35335176
复制相似问题