2
votes

I am writing a Windows Phone 8 app, and I am having some problems with the UI. I want a control that will stretch to the width of the whole screen, and will flow its children controls horizontally (to fill the space).

Currently, I have a a StackPanel with Orientation = Horizontal, but it doesn't allow the children control (a slider) to have a HorizontalAlignment=Stretch (that actually stretches). I can manually strech the slider, but I don't want to have hardcoded sizes..

Here is the code:

<StackPanel Orientation="Horizontal">
    <TextBlock Text="Hue Bins"  />
    <Slider x:Name="HueBins" VerticalAlignment="Bottom" HorizontalAlignment="Stretch"  Value="24" Maximum="36" Minimum="1"/>
</StackPanel>

and the resulting image:

enter image description here

In normal WPF, there is the Dockpanel control, but that doesn't seem to exist for WP8. Is there anyway to emulate that behavior?

2

2 Answers

7
votes

You can use Grid with two columns:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <TextBlock Text="Hue Bins"  />
    <Slider x:Name="HueBins" Grid.Column="1" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Value="24" Maximum="36" Minimum="1"/>
</Grid>
0
votes

You could try the version extracted from Silverlight Toolkit here, with some adjustments they did for WP7 http://www.geekchamp.com/articles/using-dockpanel-in-wp7

or use the whole Silverlight Toolkit if you need more stuff from it http://silverlight.codeplex.com/ (since Windows Phone Toolkit that was derived from it doesn't seem to contain DockPanel)

some info (but broken download link) on what is needed to compile DockPanel are at http://matthiasshapiro.com/2010/06/28/using-wrappanel-and-dockpanel-in-windows-phone-7-with-blend/

Update: I used the info I mentioned above to set up http://DockPanel.codeplex.com. It works fine, apart from the case where all the top/left/right/bottom/middle items are all added together in the layout, at least on Windows Phone it does some wrong layout in that case