Question

I'm new to Windows phone 8 development and I am having difficulty with a panorama view.

When I create a basic 'Windows Phone Portrait Page' I have no difficulty creating grids and aligning Toolbox controls between those grids. However, with the Panorama page, when I create grids, those grids are applied to every page in the panorama and therefore I cannot use different layouts for each page.

How would I achieve different layouts on my panorama page? Should I be using a WindowsPhoneControl instead?

Thanks for your time.

<phone:PhoneApplicationPage
x:Class="SmarterPower.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait"  Orientation="Portrait"
shell:SystemTray.IsVisible="False">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="148*"/>
        <ColumnDefinition Width="225*"/>
        <ColumnDefinition Width="107*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="351*"/>
        <RowDefinition Height="201*"/>
        <RowDefinition Height="248*"/>
    </Grid.RowDefinitions>

     <!--Panorama control-->
    <phone:Panorama Title="smarter power for you" Grid.RowSpan="3" Grid.ColumnSpan="3">
        <phone:Panorama.Background>
            <ImageBrush ImageSource="/SmarterPower;component/Assets/PanoramaBackground.png"/>
        </phone:Panorama.Background>

        <!--Panorama item one-->
        <phone:PanoramaItem>
            <!--Double line list with image placeholder and text wrapping using a floating header that scrolls with the content-->
            <phone:LongListSelector Margin="0,-38,-22,2" ItemsSource="{Binding Items}" VerticalContentAlignment="Top" VerticalAlignment="Top">
                <phone:LongListSelector.ListHeaderTemplate>
                    <DataTemplate>
                        <Grid Margin="12,0,0,38">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="menu"
                                       Style="{StaticResource PanoramaItemHeaderTextStyle}"
                                       Grid.Row="0"/>
                        </Grid>
                    </DataTemplate>
                </phone:LongListSelector.ListHeaderTemplate>
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Margin="0,0,0,0" Height="50" Width="432">
                            <!--Replace rectangle with image-->
                            <Image Source="{Binding Image}" />
                            <StackPanel Width="311" Margin="8,-5,0,5">
                                <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Margin="0,5,10,0" Style="{StaticResource PhoneTextSmallStyle}" FontSize="{StaticResource PhoneFontSizeLarge}" VerticalAlignment="Center" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
            </phone:LongListSelector>
        </phone:PanoramaItem>

        <!--Panorama item two-->
        <phone:PanoramaItem>
            <TextBlock HorizontalAlignment="Left" Height="105" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="154" Margin="0,-10,0,0"/>
        </phone:PanoramaItem>
    </phone:Panorama>
</Grid>

Was it helpful?

Solution

You should define your rows and columns in a Grid control inside a panorama item, instead of defining them in the layout root grid:

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">


    <!--Panorama control-->
    <phone:Panorama Title="My Panorama" >

        <!--Panorama item one-->
        <phone:PanoramaItem Header="item 1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="148*"/>
                    <ColumnDefinition Width="225*"/>
                    <ColumnDefinition Width="107*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="351*"/>
                    <RowDefinition Height="201*"/>
                    <RowDefinition Height="248*"/>
                </Grid.RowDefinitions>
            </Grid>
        </phone:PanoramaItem>

        <!--Panorama item two-->
        <phone:PanoramaItem Header="item 2">              
        </phone:PanoramaItem>
    </phone:Panorama>
</Grid>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top