コンテナーの幅と高さを倍率として使用する、スケーリングされたPathGeometryを使用して Path を作成できます。したがって、どちらの方向にも 0 から 1 の範囲の論理座標でジオメトリを完全に指定できます。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button HorizontalAlignment="Left" Margin="5" Content="Button"/>
<Canvas x:Name="polylineCanvas" Grid.Row="1">
<Path Stroke="Blue" StrokeThickness="3">
<Path.Data>
<PathGeometry x:Name="polyline">
<PathGeometry.Transform>
<ScaleTransform
ScaleX="{Binding ActualWidth, ElementName=polylineCanvas}"
ScaleY="{Binding ActualHeight, ElementName=polylineCanvas}"/>
</PathGeometry.Transform>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
</Grid>
以下に示すように、コードでジオメトリを指定できます。
var points = new Point[]
{
new Point(0.1, 0.1),
new Point(0.9, 0.1),
new Point(0.9, 0.9),
new Point(0.1, 0.9)
};
var figure = new PathFigure
{
StartPoint = points[0],
IsClosed = true
};
var segment = new PolyLineSegment(points.Skip(1), true);
figure.Segments.Add(segment);
polyline.Figures.Add(figure);
PathGeometry の代わりにStreamGeometryを使用することもできます。