Search code examples
xamlwindows-runtimewindows-phone-8.1windows-phone

Fill width on Windows Phone 8.1


I'm developing an application using the Windows Phone 8.1 SDK, I write UI descriptions using XAML markup.

I can't get a text box to fill width.

I see similar questions already posted but they involve ListView.

I'm really confused. There seems to be no proportional sizing options. Tutorials show the use of explicit pixel counts in design.

Is that really the preferred method on Windows? How am I supposed to deal with unpredictable screen sizes in Windows?


Solution

  • The items which I had, which were failing to fill their parent, were inside a ContentControl. The ContentControl correctly filled its width, but its child, which was a Grid, would not.

    I found the solution here – https://stackoverflow.com/a/17627257/5476004 – and I will echo that solution here in case this post is found by someone else searching about the same problem.

    The ContentControl requires two special properties in order for its child element to fill the parent. They are HorizontalContentAlignment and VerticalContentAlignment. Like so":

    <ContentControl Name="MyContent" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
    …
    </ContentControl>
    

    Fill now occurs correctly.