Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to expand a Slider to fill the available space when the slider is within a StackPanel
    text
    copied!<p>Inserting a <code>Slider</code> in a <code>Grid</code> would expand it to fill the available space, but I would prefer not use a grid for the following reason:</p> <p>I've a <code>TextBlock</code> and a <code>Slider</code> in a <code>UserControl</code>, the slider is spring loaded and does jog / shuttle; the current value has to be displayed because the user can't rely on the neutral cursor's position, so the textblock. Implementing the <code>**Orientation**</code> property of this custom slider requires both components to be rotated and also their relative position to be adjusted (left/right or top/bottom), which wouldn't be easy with a grid (unless I miss something obvious) while it is with a <code>StackPanel</code>.</p> <p><strong>Response to Aviad's comment</strong></p> <p>Aviad, thanks, I apologize for the pain ;-) The question was in the title: How to expand a Slider to fill the available space when the slider is within a StackPanel ?</p> <p>This user control:</p> <pre><code>&lt;UserControl x:Class="XXX.Preview.SelectionView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="auto" Width="auto"&gt; &lt;GroupBox Header="Selected"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock/&gt; &lt;Slider/&gt; &lt;/StackPanel&gt; &lt;/GroupBox&gt; &lt;/UserControl&gt; </code></pre> <p>won't expand when included in a grid even in a row with a "*" width. The slider will have no length at all.</p> <p>A solution is to replace the stack panel by a grid in the code below, but I don't want to use a grid, because I need to use the Orientation property of the stack panel to show both controls stacked vertically when the enclosing user control is set in the Orientation "Vertical".</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