I'd like to "draw" several Polyline
s and some Textblock
s or Label
s in a Viewbox
in WPF.
Since a Viewbox
only allows a single Child, I tried to put the Polyline
s inside a Canvas
Element which didn't work:
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>
The Polyline
is correctly drawn when I use this code (i.e. I simply dropped the Canvas
):
<Viewbox Stretch="Uniform">
<Polyline
Points="{Binding Path=Points2}"
Stroke="Green"
StrokeThickness="2" >
</Polyline>
</Viewbox>
I want to visualize some geometric properties like in a very minimalistic computer geometry program like geogebra for instance. Optionally some points should be movable in a next version, but this is not essential.
Solution:
<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>
This puts to identical polygons on top of each other, i.e. thin yellow on top of wide green polyline.
The answer to this stackoverflow question helped me.