Grid size inside UserControl

Hey I was wondering if someone could help me with this problem, as I have been working on it for the course of the whole morning. Its probably something really simple but I just can't figure it out.

So, I made a UserControl with XAML. Which is right here...


Answer this question

Grid size inside UserControl

  • hokietoner

    Actually, inside the UserControl XAML (the top tag) you should set

    VerticalContentAlignment="Stretch"
    HorizontalContentAlignment="Stretch"

    Note the extra "Content" part of it. If you don't it will not scale correctly. Skip the HorizontalAlignment bits inside the control.


  • J Tatta

    I tried it again... and I did get that to work. I guess I wasn't paying attention and put the ContentAlignment in the wrong section. Thanx again.

  • Aarom

    Yes, as Malmer has said, you can set the content alignment:

    <UserControl x:Class="TestUserControl.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="Blue"
    VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">



  • Ross Watson

    You may also need to set HorizontalAlignment and VerticalAlignment on the TestUserControl tag. You can also try setting the column/row sizes explicitly to With="*" and Height="*" respectively.

  • Thundermaker

    Try adding HorizontalAlignment and VerticalAlignment to the UserControl definition tag itself. The grid is going to size to the UserControl, and it is currently going to size to its content, not to the enclosing element.

    I have not tried this myself, so this is only a suggestion.



  • rod 001

    I have no idea why UserControl does that; however you can replace UserControl with ContentControl and it will work as expected.


  • ChocolateBoyWonder

    I have tried all the Vertical and Horizontal alignments, and i was unable to compile with the VertialContentAlignment and HorizontalContentAlignment properties. I think i am just going to use the ContentContainer class as this gave me exactly what i was looking for.

    Thank you for all the respones.

  • Grid size inside UserControl