以下代码似乎没有垂直居中;例如在排列线时似乎没有考虑到行程厚度:
<Grid VerticalAlignment="Center" Width="32" Height="32">
<Line Stretch="None" HorizontalAlignment="Stretch" VerticalAlignment="Center" X2="32"
Stroke="Black"
StrokeThickness="{Binding StrokeThickness}" />
</Grid>
缺少什么?
答案 0 :(得分:1)
我认为这可能与StrokeThickness
有关,但未更改DesiredSize
元素的Line
,但您可以解决此问题:
Grid
可以替换为Canvas
:
<Canvas VerticalAlignment="Center" Width="32" Height="32">
<Line Stretch="None" X2="32" Y1="16" Y2="16"
Stroke="Black"
StrokeThickness="15" />
</Canvas>
或者,如果您需要外部Grid
,请将Line
包裹在Canvas
中:
<Grid VerticalAlignment="Center" Width="32" Height="32" >
<Canvas VerticalAlignment="Center">
<Line Stretch="None" X2="32"
Stroke="Black"
StrokeThickness="15" />
</Canvas>
</Grid>