fuzzomorphism
fuzzomorphism

Reputation: 77

Resize polygon in to fill in Canvas

How can i resize Polygon which is placed in Canvas so it fills that canvas?

I don't want to change values of polygon points, I just want it to be displayed inside of canvas in case polygon coordinates are too large, too small or out of screen.

Upvotes: 1

Views: 1872

Answers (2)

PJRobot
PJRobot

Reputation: 1416

Came across this problem recently and worked out a solid solution:

<Canvas x:Name="CanvasName">
    <Polygon Points="{Binding Path=PointCollectionName}" Stretch="Fill" Fill="Black"
        Width={Binding ElementName=CanvasName, Path=ActualWidth}"
        Height={Binding ElementName=CanvasName, Path=AcutalHeight}"/>
</Canvas> 

Upvotes: 1

gomi42
gomi42

Reputation: 2519

Do you have the chance to replace the Canvas with a Grid? If so just set the Stretch attribute of the polygon, e.g. Uniform keeps the aspect ratio:

  <Grid Width="297" Height="159">
    <Polygon Points="10,110 110,110 110,10" Fill="Blue" Stretch="Uniform" />
  </Grid>

Upvotes: 0

Related Questions