[英]Several Polylines in a Viewbox using WPF
我想在WPF的Viewbox
中“绘制”一些Polyline
和一些Textblock
或Label
。
由于Viewbox
只允许一个Child,因此我尝试将Polyline
放入无法使用的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>
当我使用此代码时(即,我只是放下Canvas
)正确绘制了Polyline
:
<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问题的答案对我有所帮助。
画布实际上不适用于这样的事情,一旦将控件放入画布中,就会忽略所有布局。 您是否可以将折线放置在网格中并使用边距定位它们?
<Viewbox Stretch="Uniform">
<Grid Margin="10">
<Polyline
Points="{Binding Path=Points2}"
Stroke="Green"
StrokeThickness="2" >
</Polyline>
</Grid>
</Viewbox>
之所以看不到折线,是因为“ 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.