使用Windows Phone 7的Silverlight创建表 [英] Creating a table with Silverlight for Windows Phone 7

查看:75
本文介绍了使用Windows Phone 7的Silverlight创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在WP7上创建一个表格。这是我当前使用的方法,使用带有网格的ListBox作为数据模板。

I'd like to create a table on WP7. This is my current approach using a ListBox with a Grid as the data template.

<ListBox x:Name="ResultsList" Margin="12,0" Grid.Row="1">
    <ListBox.Resources>
        <DataTemplate x:Key="ResultsListItem">
            <Grid d:DesignWidth="385" Height="28">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="88"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBlock x:Name="textBlock1" Margin="0,0,24,0"/>
                <TextBlock x:Name="textBlock2" Margin="0,0,24,0"
                    VerticalAlignment="Top" Grid.Column="1"/>
                <TextBlock x:Name="textBlock3" Margin="0,0,24,0" 
                    VerticalAlignment="Top" Grid.Column="3"/>
            </Grid>
        </DataTemplate>
    </ListBox.Resources>
    <ListBox.ItemTemplate>
        <StaticResource ResourceKey="ResultsListItem"/>
    </ListBox.ItemTemplate>
</ListBox>

问题是,结果表的列大小不相等。网格的列定义适用于每一行,而与其他行无关。这意味着,如果textBlock1中有长文本,则列0将更大。在下一行中,textBlock1中的文本可能更短,导致第0列也比上一行中的第0列短。

The problem is, that the resulting table's columns are not sized equally. The Grid's column definitions are applied to each row independently of the other rows. That means, if there is a long text in textBlock1, column 0 will be larger. In the next row there could be a shorter text in textBlock1, resulting in column 0 also being shorter than the column 0 in the previous row.

所有列如何行大小是否相等?我不想使用固定宽度,因为当方向从纵向更改为横向时,列会自动调整大小。

How can the columns in all rows be sized equally? I don't want to use fixed width because when the orientation changes from portrait to landscape the colums would resize automatically.

有HeaderedItemsControl,但据我所知不适用于Windows Phone 7?

There is the HeaderedItemsControl, but as I understand it it is not available for Windows Phone 7?

推荐答案

这是一个棘手的问题!在WPF中,存在SharedSizeGroup的概念,该概念允许您在多个网格之间共享列宽,但这在Silverlight中不可用。

This is a tricky problem! In WPF there exists the concept of a SharedSizeGroup, which allows you to share column widths across multiple grids, but this is not available in silverlight.

有一些解决方法网络上:

There are a few workarounds on the web:

http://www.scottlogic.co.uk/blog/colin/2010/11/using-a-grid-as-the-panel- for-an-itemscontrol /

http://databaseconsultinggroup.com/blog/2009/05/simulating_sharedsizegroup_in.html

虽然都不是简单的解决方案。

Although neither are simple solutions.

您还可以尝试使用Mike的AutoGrid:

You might also try Mike's AutoGrid:

http://whydoidoit.com/2010/10/06/automatic-grid-layout-for-silverlight/

这篇关于使用Windows Phone 7的Silverlight创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆