Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A Viewbox can only "visually" scale its child element, including the thickness of any rendered stroke. What you need is a scaling that only applies to the geometry of the lines (or other shapes), but leaves the stroke unaffected.</p> <p>Instead of using <code>Line</code> objects, you could draw your lines by <a href="http://msdn.microsoft.com/en-us/library/ms615632.aspx" rel="noreferrer"><code>Path</code></a> objects that use transformed <a href="http://msdn.microsoft.com/en-us/library/ms635204.aspx" rel="noreferrer">LineGeometries</a> for their <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.path.data.aspx" rel="noreferrer"><code>Data</code></a> property. You could create a <a href="http://msdn.microsoft.com/en-us/library/ms635521.aspx" rel="noreferrer"><code>ScaleTransform</code></a> that scales from logical coordinates to viewport coordinates by using the Grid's width and height as scaling factors in x and y direction. Each LineGeometry (or any other Geometry) would use logical coordinates in the range 0..1:</p> <pre><code>&lt;Grid x:Name="grid"&gt; &lt;Grid.Resources&gt; &lt;ScaleTransform x:Key="transform" ScaleX="{Binding ActualWidth, ElementName=grid}" ScaleY="{Binding ActualHeight, ElementName=grid}"/&gt; &lt;/Grid.Resources&gt; &lt;Path Stroke="Black" StrokeThickness="1"&gt; &lt;Path.Data&gt; &lt;LineGeometry StartPoint="0.1,0.1" EndPoint="0.9,0.9" Transform="{StaticResource transform}"/&gt; &lt;/Path.Data&gt; &lt;/Path&gt; &lt;/Grid&gt; </code></pre> <hr> <p>In order to get a uniform scaling you may simply bind both the ScaleTransform's <code>ScaleX</code> and <code>ScaleY</code> properties to either the <code>ActualWidth</code> or <code>ActualHeight</code> of the Grid:</p> <pre><code>&lt;Grid x:Name="grid"&gt; &lt;Grid.Resources&gt; &lt;ScaleTransform x:Key="transform" ScaleX="{Binding ActualWidth, ElementName=grid}" ScaleY="{Binding ActualWidth, ElementName=grid}"/&gt; &lt;/Grid.Resources&gt; ... &lt;/Grid&gt; </code></pre> <p>You may also calculate the uniform scaling factor from the minimum value of the width and height, with a bit of code behind:</p> <pre><code>&lt;Grid x:Name="grid" SizeChanged="grid_SizeChanged"&gt; &lt;Grid.Resources&gt; &lt;ScaleTransform x:Key="transform"/&gt; &lt;/Grid.Resources&gt; ... &lt;/Grid&gt; </code></pre> <p>with a SizeChanged handler like this:</p> <pre><code>private void grid_SizeChanged(object sender, SizeChangedEventArgs e) { var transform = grid.Resources["transform"] as ScaleTransform; var minScale = Math.Min(grid.ActualWidth, grid.ActualHeight); transform.ScaleX = minScale; transform.ScaleY = minScale; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload