我想“画”几个Polyline
和一些Textblock
或Label
在一个Viewbox
的WPF。
由于Viewbox
只允许一个子元素,所以我尝试将Polyline
s放在一个Canvas
元素中,但没有起作用:
XAML:
<Viewbox Stretch="Uniform">
<Canvas Margin="10">
<Polyline
Points="{Binding Path=Points2}"
Stroke="Green"
StrokeThickness="2" >
</Polyline>
<!-- other Polylines, Textblocks etc. would go here... -->
</Canvas>
</Viewbox>
当我使用下面的代码时,Polyline
是正确绘制的(即,我只是简单地删除了Canvas
):
<Viewbox Stretch="Uniform">
<Polyline
Points="{Binding Path=Points2}"
Stroke="Green"
StrokeThickness="2" >
</Polyline>
</Viewbox>
我想要可视化一些几何属性,比如在一个非常简约的计算机几何程序中,比如geogebra。有些点在下一个版本中应该是可移动的,但这不是必需的。
解决方案:
<Viewbox Stretch="Uniform">
<Grid>
<Polyline
Points="{Binding Path=Points2}"
Stroke="Green"
StrokeThickness="4" >
</Polyline>
<Polyline
Points="{Binding Path=Points2}"
Stroke="Yellow"
StrokeThickness="2" >
</Polyline>
</Grid>
</Viewbox>
这会将相同的多边形放在彼此的顶部,即宽绿色多段线顶部的黄色细线。
这个stackoverflow question的答案帮助了我。
发布于 2013-07-08 15:24:23
画布并不适用于这样的事情,一旦你把你的控件放在画布中,你就会忽略所有的布局。你可以把你的折线放在网格里面,然后用边距来定位它们吗?
<Viewbox Stretch="Uniform">
<Grid Margin="10">
<Polyline
Points="{Binding Path=Points2}"
Stroke="Green"
StrokeThickness="2" >
</Polyline>
</Grid>
</Viewbox>
发布于 2013-07-08 15:55:33
看不到多段线的原因是因为Canvas
具有默认的Height
和Width
0。
尝试显式设置Height
和Width
。
<Viewbox x:Name="ViewBox" Stretch="Uniform">
<Canvas x:Name="chartCanvas" Margin="10" Height="200" Width="300">
<Polyline
Points="{Binding Path=Points2}"
Stroke="Green"
StrokeThickness="2">
</Polyline>
<!-- other Polylines, Textblocks etc. would go here... -->
</Canvas>
</Viewbox>
https://stackoverflow.com/questions/17530237
复制相似问题