locked
Get Slider to fit the size of the containing Grid column RRS feed

  • Question

  • I have a simple Grid - 3 rows 2 cols.

    Each row has a) TextBlock then b) Slider.

    The cols are defined as width = 100 and 300 respectively.

    Neither the TextBlocks nor the Sliders have any individual explicit width specified in the XAML.

    The text blocks all look good - in the sense the fit inside their column aligned to the left. Their width value in the properties is stuff like "Auto(31.77)" no doubt the actual length of the rendered text.

    When I hover the mouse over the TextBlock in the designer, I see a small rectangle who's width is that of the column width.

    The sliders all look like simple white squares, no horizontal body is drawn.

    When I hover my mouse over the Slider in the designer, I see a small rectangle that is the outline of the white square - it is NOT the width of the column (as it is for the TextBlock).

    The Sliders widths in the properties are stuff like "Auto(11)"

    How do I get the width of the Slider to simply default to the width of the Grid column it is situated within?

    NOTE: The Height of the Sliders as seen in the Properties IS the same as the Height specified for the Grid row.

    Cap'n


    Tuesday, October 29, 2013 5:36 PM

Answers

All replies

  • Set the slider's Horizontal Alignment to Stretch:

     <Slider Grid.Column="1" HorizontalAlignment="Stretch" />
           

    --Rob

    Tuesday, October 29, 2013 5:47 PM
    Moderator
  • Set the slider's Horizontal Alignment to Stretch:

     <Slider Grid.Column="1" HorizontalAlignment="Stretch" />
           

    --Rob

    Yup, that's it - and I recall reading this when I first read about XAML but then promptly forgot once I moved onto a coding task..

    Thx

    Tuesday, October 29, 2013 5:54 PM