Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Working on a windows universal app. I'm having difficulty in expanding a stackpanel to occupy the entire screen width on various devices. I'd like for the contents of the stackpanel to fill the entire screen for all devices.

XAML:
XML
<Grid x:Name="RootLayout" Background="LightGray">
      <Grid.RowDefinitions>
          <RowDefinition Height="70" />
          <RowDefinition Height="55" />
          <RowDefinition Height="*" />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>
      <!-- Title Bar -->
      <Grid x:Name="TitleBar" Grid.Row ="0" Background="#FF2D8F9A">
          <TextBlock x:Name="txtTitle" TextWrapping="Wrap" Text="News" SelectionHighlightColor="{x:Null}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24"/>
      </Grid>
      <Grid x:Name="Toogle" Grid.Row ="1" Background="#FFCCCCCC" HorizontalAlignment="Center" VerticalAlignment="Center" Width="400">
          <ToggleButton x:Name="tbNews" Margin="202,-2,34,-1" Background="#FFB9B6B6" BorderBrush="Black" Content="In The News" Height="58" IsDoubleTapEnabled="False" IsHoldingEnabled="False" IsRightTapEnabled="False" Click="tbNews_Click" Style="{StaticResource CHSToggleButtonStyle}" HorizontalAlignment="Stretch"/>
          <ToggleButton x:Name="tbAnnouncements" Margin="0,-2,197,-1" Background="LightGray" BorderBrush="Black" Content="Announcements" Width="164" Height="58" FontFamily="Global User Interface" IsDoubleTapEnabled="False" IsHoldingEnabled="False" IsRightTapEnabled="False" IsChecked="False" Click="tbAnnouncements_Tapped" Style="{StaticResource CHSToggleButtonStyle}" HorizontalAlignment="Right"/>
      </Grid>
      <Grid x:Name="Content" Grid.Row ="2" Margin="0,0,0,0" HorizontalAlignment="Center">
          <StackPanel Name="Items" Orientation="Horizontal" HorizontalAlignment="Stretch">
              <ListBox HorizontalAlignment="Stretch" Name="Articlelist" BorderThickness="1" IsDoubleTapEnabled="False" IsHoldingEnabled="False" IsRightTapEnabled="False" FontFamily="Global User Interface" Tapped="Phonelist_Tapped" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Top" Margin="0,0,0,0"  >
                  <ListBox.ItemTemplate>
                      <DataTemplate>
                          <Border BorderThickness="0, 0, 0, 1" BorderBrush="Black">
                              <StackPanel Orientation="Horizontal">
                                  <StackPanel HorizontalAlignment="Stretch" Name="LocationDetails" VerticalAlignment="Center" Margin="0">
                                      <TextBlock Height="auto" Width="350"  Text="{Binding Title}" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="WrapWholeWords" Foreground="Black"  FontSize="18" FontFamily="Global User Interface" SelectionHighlightColor="#FFD7D6D8" Margin="6" FontWeight="Bold" Padding="0,0,0,0" />
                                      <TextBlock Height="auto" Width="350" Foreground="Black" FontSize="18" Text="{Binding Teaser}" FontFamily="Global User Interface" Margin="6" SelectionHighlightColor="#FFF8F7F9" TextWrapping="WrapWholeWords" Padding="2" HorizontalAlignment="Left"/>
                                  </StackPanel>
                                  <Image Source="Assets/rt_carrot~ipad.png" Height="25" Width="15" VerticalAlignment="Center" Margin="6" Stretch="UniformToFill" HorizontalAlignment="Center"/>
                              </StackPanel>
                          </Border>
                      </DataTemplate>
                  </ListBox.ItemTemplate>
              </ListBox>
          </StackPanel>
      </Grid>
  </Grid>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900