2

嗨,我正在开发 windows phone 8 应用程序。我想以网格视图格式显示图像,我在网格内使用列表框,但我的输出没有任何变化。我的代码如下,我想在网格视图上显示数据格式。

<Grid x:Name="ContentPanel" Margin="0,115,0,0" Background="#424340" Grid.RowSpan="5" />

    <StackPanel Margin="0,0,0,0.083" Grid.Row="2"  VerticalAlignment="Top" HorizontalAlignment="Center" Grid.RowSpan="2">
        <ListBox x:Name="List12" ItemsSource="{Binding}"  VerticalAlignment="Top" SelectionChanged="NotchsList12_SelectionChanged"
           Margin="0,0,0,0"  HorizontalAlignment="left" Width="Auto"  Grid.RowSpan="2">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"  VerticalAlignment="Top">
                    </StackPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Text="{Binding Titles}" Foreground="Black" Width="189" Height="34" TextWrapping="Wrap" Padding="0,0,0,0"></TextBlock>

                        <Image Source="{Binding Images}"  Width="189" Height="195" Name="value"  Stretch="Fill" VerticalAlignment="Top" ></Image>
                        <TextBlock Text="Text1" Margin="0,0,10,0" HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="1" />

                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel>

</Grid>


XDocument xmlDoc = XDocument.Parse(dataInXmlFile);

            var query = from l in xmlDoc.Descendants("Category")
                        select new Class
                        {
                            Titles = l.Attribute("title").Value,
                            Images = l.Attribute("image").Value,

                       Articles = l.Element("SubCategory").Elements("Subcategory")
                                         .Select(article => new Subclass
                                         {
                                             name = article.Attribute("name").Value,

                                             Subimage = article.Attribute("subimage").Value,
                                             Product = article.Element("Product").Elements("product")
                                                            .Select(articles => new Product
                                                            {
                                                                Price = articles.Element("productprice").Value,
                                                                ProductName = articles.Attribute("name").Value,
                                                                ProductImage = articles.Element("productimage").Value,
                                                                Shortdescription = articles.Element("productshortdiscription").Value
                                                            }).ToList(),

                                         })
                                         .ToList(),



                        };

            foreach (var result in query)
            {
                Console.WriteLine(result.Titles);
                Console.WriteLine(result.Images);

            }

            List12.DataContext = query;

我得到了如下所示

1.门 2.窗 3.桌子 4.椅子

我需要如下图所示

1.门 2.窗

3.桌子 4.椅子

4

2 回答 2

0

不要使用网格,而是使用 LongListSelector 使用 LayoutMode=Grid

例子:

<phone:LongListSelector ItemsSource="{Binding Categories}" LayoutMode="Grid" GridCellSize="200,200">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Border Background="#e67e22" Height="190" Width="190" Margin="6,0,0,0" Tap="Border_Tap" >
<TextBlock Text="{Binding Name}"></TextBlock>
</Border>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
于 2013-12-18T11:16:25.080 回答
0

做你的stackPanel方向Vertical而不是Horizontal

            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Vertical"  VerticalAlignment="Top">
                    </StackPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
于 2013-06-18T06:52:28.213 回答