Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I realised that what I needed was for the <code>Line</code> to ask for zero space during the measure step of <a href="http://msdn.microsoft.com/en-us/library/ms745058.aspx" rel="nofollow noreferrer">layout</a>, but then use up all the available space during the arrange step. I happened to stumble across the question <a href="https://stackoverflow.com/questions/4854079/make-wpf-sl-grid-ignore-a-child-element-when-determining-size">Make WPF/SL grid ignore a child element when determining size</a> which introduced the approach of using a custom decorator which included this logic.</p> <pre><code>public class NoSizeDecorator : Decorator { protected override Size MeasureOverride(Size constraint) { // Ask for no space Child.Measure(new Size(0,0)); return new Size(0, 0); } } </code></pre> <p>(I was hoping that some existing layout control incorporated this logic to avoid having to write my own layout logic, however the logic here is so simple that I'm not really that fussed). The modified XAML then becomes</p> <pre><code>&lt;ScrollViewer HorizontalScrollBarVisibility="Auto"&gt; &lt;StackPanel&gt; &lt;Button Width="400" Height="50" VerticalAlignment="Top" Margin="10" /&gt; &lt;local:NoSizeDecorator Height="1"&gt; &lt;Line Stroke="Black" HorizontalAlignment="Stretch" X2="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" StrokeDashArray="2 2" StrokeThickness="1" /&gt; &lt;/local:NoSizeDecorator&gt; &lt;/StackPanel&gt; &lt;/ScrollViewer&gt; </code></pre> <p>This works perfectly</p>
 

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