Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone 8.1 Two Column Gridview Within Pivot

I am having trouble displaying a two column gridview in a Windows Phone 8.1 application.

This is my intended result:
enter image description here

After reviewing other SO questions dealing with similar issues, I produced the following code:

 <Canvas>

    <Grid Tapped="Grid_Tapped">
        <Grid.RowDefinitions>
            <RowDefinition Height="93*"/>
            <RowDefinition Height="35*"/>
        </Grid.RowDefinitions>


        <Pivot  Name="centerPivot" Margin="0,109,0,0" Grid.Row="0" Grid.RowSpan="2" Canvas.ZIndex="2" Tapped="centerPivot_Tapped">
            <PivotItem Name="FindPivotItem" Margin="11,10,13,0.333">
                <PivotItem.Header>
                    <Grid>
                        <TextBlock Name="FindTitle" FontSize="31" Text="Store Finds" Foreground="#FF878787" FontFamily="Global User Interface" />
                    </Grid>
                </PivotItem.Header>
                <!--<GridView 
                  ScrollViewer.VerticalScrollBarVisibility="Visible" 

                  ItemTemplate="{Binding ManyListingStyle}"

                  Grid.Row="1" 
                  VerticalAlignment="Top" 
                  VerticalContentAlignment="Top" Height="450" Margin="0,0,-0.167,0" 
             />-->

                <GridView 

                Name="GridGridView"

                ItemsSource="{Binding}"
                Grid.Row="4"
                IsSwipeEnabled="True" 
                SelectionMode="Single" 
                ScrollViewer.VerticalScrollBarVisibility="Visible"
                ScrollViewer.VerticalScrollMode="Enabled" Margin="0,0,0,0.333" HorizontalAlignment="Left"
                >
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapGrid Orientation="Vertical"
                                  MaximumRowsOrColumns="3"

                                  >

                            </WrapGrid>
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                    <GridView.ItemTemplate>
                        <DataTemplate>

                            <Grid HorizontalAlignment="Left" Width="190" Height="240">
                                <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="193" Stroke="Black" VerticalAlignment="Top" Width="176" Margin="0,0,0,-8"/>
                                <Image HorizontalAlignment="Left" Height="128" Margin="13,8,0,0" VerticalAlignment="Top" Width="150" Source="Assets/example.jpg"/>
                                <TextBlock HorizontalAlignment="Left" Margin="13,141,0,0" TextWrapping="Wrap" Text="{Binding title}" VerticalAlignment="Top" Foreground="Black" FontSize="16" Width="150" FontFamily="Global User Interface"/>
                                <TextBlock HorizontalAlignment="Left" Margin="118,165,0,0" TextWrapping="Wrap" Text="{Binding price}" VerticalAlignment="Top" Foreground="#FFFF9700" FontSize="16" Width="48"/>

                            </Grid>


                        </DataTemplate>
                    </GridView.ItemTemplate>
                    <GridView.ItemContainerStyle>
                        <Style TargetType="FrameworkElement">

                        </Style>
                    </GridView.ItemContainerStyle>

                    <!--<Grid Margin="214,10,10,421">
                <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="209" Stroke="Black" VerticalAlignment="Top" Width="176"/>
                <Image HorizontalAlignment="Left" Height="150" Margin="13,8,0,0" VerticalAlignment="Top" Width="150" Source="{Binding}"/>
                <TextBlock HorizontalAlignment="Left" Margin="13,163,0,0" TextWrapping="Wrap" Text="{Binding GetListTitle}" VerticalAlignment="Top" Foreground="Black" FontSize="16" Width="150"/>
                <TextBlock HorizontalAlignment="Left" Margin="115,187,0,0" TextWrapping="Wrap" Text="{Binding GetPrice}" VerticalAlignment="Top" Foreground="#FFFF9700" FontSize="16" Width="48"/>

            </Grid>-->
                    <!--</GridView.ItemTemplate>-->
                </GridView>

            </PivotItem>
        </Pivot>
        <Rectangle x:Name="ScreenDimRectangle" Fill="#FF555453" HorizontalAlignment="Left" Height="640" Stroke="Black" VerticalAlignment="Top" Width="400" Opacity="0.5"
               Grid.Row="0" Grid.RowSpan="2" Visibility="Collapsed" Canvas.ZIndex="9"/>


    </Grid>
</Canvas>

This code, however, when bound to a list element with 8 objects, displays the following: Produced Layout

This layout also does not scroll .

After researching the around the web heavily, I believe I am quite stuck. I would think that the WrapGrid and MaximumRowsOrColumns settings should be what I am really after here, and their settings should (at least according to others) produce my intended result.

My Binding Code:

//Create new Fake Listings
        var listings = new List<Listing>();

        var fakelisting1 = new Listing();
        fakelisting1.title = "Brand new Product!";
        fakelisting1.price = "9.99";
        listings.Add(fakelisting1);

        var fakelisting2 = new Listing();
        fakelisting2.title = "Here is the new Product!";
        fakelisting2.price = "19.99";
        listings.Add(fakelisting2);

        var fakelisting3 = new Listing();
        fakelisting3.title = "Here is the new 2Product!";
        fakelisting3.price = "29.99";
        listings.Add(fakelisting3);

        var fakelisting4 = new Listing();
        fakelisting4.title = "Here is the new 3Product!";
        fakelisting4.price = "39.99";
        listings.Add(fakelisting4);

        var fakelisting5 = new Listing();
        fakelisting5.title = "Here is the new 4Product!";
        fakelisting5.price = "49.99";
        listings.Add(fakelisting5);

        var fakelisting6 = new Listing();
        fakelisting6.title = "Here is the new 5Product!";
        fakelisting6.price = "59.99";
        listings.Add(fakelisting6);

        var fakelisting7 = new Listing();
        fakelisting7.title = "Here is the new 6Product!";
        fakelisting7.price = "49.99";
        listings.Add(fakelisting7);

        var fakelisting8 = new Listing();
        fakelisting8.title = "Here is the new 7Product!";
        fakelisting8.price = "49.99";
        listings.Add(fakelisting8);

        GridGridView.DataContext = listings;

Why am I not seeing that result?

like image 404
JcKelley Avatar asked Nov 09 '22 09:11

JcKelley


1 Answers

What I've done:

  • when you want your items in WrapGrid be placed horizontally first, use Orientation=Horizontal,
  • I've changed the item's grid width to 180, when it was 190 then items were placed vertically, as on my screen the width was too small,
  • I've changed MaximumRowsOrColumns to 2 as you want two items horizontally,
  • I've removed the ScrollViewer information - it's being applied automatically by GridView.
  • I've removed Canvas, so the GridView knows how much place it has.

The code look like this:

<Grid Margin="0,150,0,0" Tapped="Grid_Tapped" >
    <Grid.RowDefinitions>
        <RowDefinition Height="93*"/>
        <RowDefinition Height="35*"/>
    </Grid.RowDefinitions>

    <Pivot Name="centerPivot" Margin="0,0,0,0" Grid.Row="0" Grid.RowSpan="2" Canvas.ZIndex="2" Tapped="centerPivot_Tapped">
        <PivotItem Name="FindPivotItem" Margin="11,10,13,0.333">
            <PivotItem.Header>
                <Grid>
                    <TextBlock Name="FindTitle" FontSize="31" Text="Store Finds" Foreground="#FF878787" FontFamily="Global User Interface" />
                </Grid>
            </PivotItem.Header>

            <GridView Name="GridGridView" ItemsSource="{Binding}"
                      SelectionMode="Single" Margin="0,0,0,0.333" HorizontalAlignment="Left">
                <GridView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="2"/>
                    </ItemsPanelTemplate>
                </GridView.ItemsPanel>
                <GridView.ItemTemplate>
                    <DataTemplate>
                        <Grid HorizontalAlignment="Left" Width="180" Height="240">
                            <Rectangle Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="193" Stroke="Black" VerticalAlignment="Top" Width="176" Margin="0,0,0,-8"/>
                            <Image HorizontalAlignment="Left" Height="128" Margin="13,8,0,0" VerticalAlignment="Top" Width="150" Source="Assets/example.jpg"/>
                            <TextBlock HorizontalAlignment="Left" Margin="13,141,0,0" TextWrapping="Wrap" Text="{Binding title}" VerticalAlignment="Top" Foreground="Black" FontSize="16" Width="150" FontFamily="Global User Interface"/>
                            <TextBlock HorizontalAlignment="Left" Margin="118,165,0,0" TextWrapping="Wrap" Text="{Binding price}" VerticalAlignment="Top" Foreground="#FFFF9700" FontSize="16" Width="48"/>
                        </Grid>
                    </DataTemplate>
                </GridView.ItemTemplate>
            </GridView>
        </PivotItem>
    </Pivot>
</Grid>

And the result:

Items

like image 53
Romasz Avatar answered Nov 14 '22 21:11

Romasz